feat: harden workspace file APIs
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
c1b8982e3b
commit
04b309d3fc
@@ -117,10 +117,13 @@ func (l *LocalFS) Mkdir(path string) error {
|
||||
|
||||
// Remove removes path (file or directory recursively).
|
||||
func (l *LocalFS) Remove(path string) error {
|
||||
abs, _, err := l.resolve(path)
|
||||
abs, rel, err := l.resolve(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if rel == "." {
|
||||
return util.New(util.CodeBadRequest, "cannot remove workspace root")
|
||||
}
|
||||
if err := os.RemoveAll(abs); err != nil {
|
||||
return util.Wrap(util.CodeInternal, "failed to remove path", err)
|
||||
}
|
||||
|
||||
@@ -135,3 +135,12 @@ func TestLocalFSListSorted(t *testing.T) {
|
||||
t.Errorf("List not sorted: %v", names)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLocalFSRejectsRemoveRoot(t *testing.T) {
|
||||
fsys := NewLocal(t.TempDir())
|
||||
for _, path := range []string{"", "."} {
|
||||
if err := fsys.Remove(path); err == nil {
|
||||
t.Fatalf("Remove(%q) expected error", path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user