Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions docs/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions mirror/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions mirror/mirror_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
Loading