diff --git a/CHANGELOG.md b/CHANGELOG.md index 3128447..6e80514 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Preserve whitespace in FTS table names during optimization so a similarly named table is not modified instead. +- Keep SQLite sidecar cleanup in the selected mirror root when its path contains surrounding whitespace, rather than deleting sidecars from a neighboring directory. + - Keep scoped mirror commits limited to literal file and directory selections, so bracketed filenames do not include matching neighboring files. - Preserve whitespace in selected mirror commit paths so a similarly named file is not committed instead. diff --git a/docs/packages.md b/docs/packages.md index 9e5a74b..d8846d6 100644 --- a/docs/packages.md +++ b/docs/packages.md @@ -44,6 +44,9 @@ sidecars. Nonpositive limits leave file size unbounded. and validating repository-relative paths. Git glob patterns and pathspec magic are not expanded. Use `.` to commit the whole archive. +`mirror.CleanSQLiteSidecars` preserves whitespace in the selected root path; +it rejects an empty or whitespace-only root instead of selecting another tree. + Managed sidecar trees reject overlapping source and destination roots, including mixed relative and absolute paths. Configured root symlinks remain supported; symlink directories inside a destination copy path are rejected so copying and diff --git a/mirror/mirror.go b/mirror/mirror.go index e68d152..74da0d5 100644 --- a/mirror/mirror.go +++ b/mirror/mirror.go @@ -358,9 +358,9 @@ func Dirty(ctx context.Context, opts Options) (bool, error) { return strings.TrimSpace(out) != "", nil } +// CleanSQLiteSidecars removes SQLite sidecars beneath the literal root path. func CleanSQLiteSidecars(rootDir string) (int, error) { - rootDir = strings.TrimSpace(rootDir) - if rootDir == "" { + if strings.TrimSpace(rootDir) == "" { return 0, errors.New("root dir is required") } count := 0 diff --git a/mirror/mirror_test.go b/mirror/mirror_test.go index 9b46155..1e71e09 100644 --- a/mirror/mirror_test.go +++ b/mirror/mirror_test.go @@ -773,6 +773,37 @@ func TestSyncCurrentForWritePreservesLegacyBranch(t *testing.T) { } } +func TestCleanSQLiteSidecarsPreservesSelectedRoot(t *testing.T) { + roots := []string{" share"} + if runtime.GOOS != "windows" { + roots = append(roots, "share ") + } + for _, root := range roots { + t.Run(root, func(t *testing.T) { + t.Chdir(t.TempDir()) + for _, dir := range []string{root, "share"} { + if err := os.Mkdir(dir, 0o700); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(dir, "archive.db-wal"), []byte(dir), 0o600); err != nil { + t.Fatal(err) + } + } + removed, err := CleanSQLiteSidecars(root) + if err != nil || removed != 1 { + t.Fatalf("cleanup = %d, %v; want one selected sidecar removed", removed, err) + } + if _, err := os.Stat(filepath.Join(root, "archive.db-wal")); !os.IsNotExist(err) { + t.Errorf("selected sidecar still exists: %v", err) + } + data, err := os.ReadFile(filepath.Join("share", "archive.db-wal")) + if err != nil || string(data) != "share" { + t.Errorf("neighboring sidecar changed: %q, %v", data, err) + } + }) + } +} + func TestCleanSQLiteSidecars(t *testing.T) { dir := t.TempDir() files := []string{"archive.db", "archive.db-wal", "archive.db-shm", "notes.txt"}