fix(config): allow project configs at a volume root

The containment check appended a separator to the project root. For a
project at / or C:\ the root already ends with one, so the prefix became
// or C:\\ and every save of that project's config was refused as
linking outside the project.
This commit is contained in:
Willie
2026-10-07 10:54:06 +08:00
parent 11c2821350
commit f5a5e920c8
2 changed files with 9 additions and 1 deletions
+3 -1
View File
@@ -79,7 +79,9 @@ func ConfigWritePath(path string, project bool) (string, error) {
return dest, nil
}
root := resolveExisting(filepath.Dir(filepath.Dir(path)))
if !PathHasPrefix(dest, root+string(filepath.Separator)) {
// A project at a volume root (/ or C:\) already ends with the separator.
sep := string(filepath.Separator)
if !PathHasPrefix(dest, strings.TrimSuffix(root, sep)+sep) {
return "", fmt.Errorf("%s links outside the project to %s; replace the link with a regular file", path, dest)
}
return dest, nil
+6
View File
@@ -113,6 +113,12 @@ func TestConfigWritePath(t *testing.T) {
t.Fatalf("expected refusal, got %v", err)
}
})
t.Run("project at the volume root is allowed", func(t *testing.T) {
p := filepath.Join(string(filepath.Separator), ".skillshare-volume-root-test", "config.yaml")
if _, err := ConfigWritePath(p, true); err != nil {
t.Fatalf("unexpected error: %v", err)
}
})
t.Run("new project config is allowed", func(t *testing.T) {
p := filepath.Join(root, "new", ".skillshare", "config.yaml")
if _, err := ConfigWritePath(p, true); err != nil {