From f5a5e920c8572bcd87bd26ad089ace050f5ff727 Mon Sep 17 00:00:00 2001 From: Willie Date: Wed, 7 Oct 2026 10:54:06 +0800 Subject: [PATCH] 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. --- internal/utils/path.go | 4 +++- internal/utils/path_test.go | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/utils/path.go b/internal/utils/path.go index fe0d4b5c1..1c8a659d3 100644 --- a/internal/utils/path.go +++ b/internal/utils/path.go @@ -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 diff --git a/internal/utils/path_test.go b/internal/utils/path_test.go index d77c8de73..f980fea0a 100644 --- a/internal/utils/path_test.go +++ b/internal/utils/path_test.go @@ -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 {