From 0fc88c4f6885ab2453e77294aee6cc7dbcc78388 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Thu, 19 Jun 2025 17:30:23 +0200 Subject: [PATCH] integration/hsic: add debugging to diagnose empty database issue Add logging to show: - Contents of /tmp directory in container - SQLite files found in container - Files found in tar archive - Extraction details and byte counts This will help identify why database extraction is resulting in empty files. --- integration/hsic/hsic.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/integration/hsic/hsic.go b/integration/hsic/hsic.go index 9d82f761..2f300795 100644 --- a/integration/hsic/hsic.go +++ b/integration/hsic/hsic.go @@ -643,6 +643,22 @@ func (t *HeadscaleInContainer) SaveDatabase(savePath string) error { return nil } + // First, let's see what files are actually in /tmp + tmpListing, err := t.Execute([]string{"ls", "-la", "/tmp/"}) + if err != nil { + log.Printf("Warning: could not list /tmp directory: %v", err) + } else { + log.Printf("Contents of /tmp in container %s:\n%s", t.hostname, tmpListing) + } + + // Also check for any .sqlite files + sqliteFiles, err := t.Execute([]string{"find", "/tmp", "-name", "*.sqlite*", "-type", "f"}) + if err != nil { + log.Printf("Warning: could not find sqlite files: %v", err) + } else { + log.Printf("SQLite files found in %s:\n%s", t.hostname, sqliteFiles) + } + tarFile, err := t.FetchPath("/tmp/integration_test_db.sqlite3") if err != nil { return fmt.Errorf("failed to fetch database file: %w", err) @@ -659,6 +675,8 @@ func (t *HeadscaleInContainer) SaveDatabase(savePath string) error { return fmt.Errorf("failed to read tar header: %w", err) } + log.Printf("Found file in tar: %s (type: %d, size: %d)", header.Name, header.Typeflag, header.Size) + // Extract the first regular file we find if header.Typeflag == tar.TypeReg { dbPath := path.Join(savePath, t.hostname+".db") @@ -673,6 +691,8 @@ func (t *HeadscaleInContainer) SaveDatabase(savePath string) error { return fmt.Errorf("failed to copy database file: %w", err) } + log.Printf("Extracted database file: %s (%d bytes written, header claimed %d bytes)", dbPath, written, header.Size) + // Check if we actually wrote something if written == 0 { return fmt.Errorf("database file is empty (size: %d, header size: %d)", written, header.Size)