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 {