mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 12:23:22 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user