Skip to content

Commit 783cae1

Browse files
committed
Remove DirectoryNotEmptyError
1 parent 2141440 commit 783cae1

File tree

7 files changed

+4
-65
lines changed

7 files changed

+4
-65
lines changed

integration/cmd/fs/rm_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ func TestFsRmNonEmptyDirectory(t *testing.T) {
9595
// Run rm command
9696
_, _, err = testcli.RequireErrorRun(t, ctx, "fs", "rm", path.Join(tmpDir, "a"))
9797
assert.ErrorIs(t, err, fs.ErrInvalid)
98-
assert.ErrorAs(t, err, &filer.DirectoryNotEmptyError{})
9998
})
10099
}
101100
}

integration/libs/filer/filer_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func commonFilerRecursiveDeleteTest(t *testing.T, ctx context.Context, f filer.F
107107
assert.Equal(t, []string{"file1", "file2", "subdir1", "subdir2"}, names)
108108

109109
err = f.Delete(ctx, "dir")
110-
assert.ErrorAs(t, err, &filer.DirectoryNotEmptyError{})
110+
require.Error(t, err)
111111

112112
err = f.Delete(ctx, "dir", filer.DeleteRecursively)
113113
assert.NoError(t, err)
@@ -210,8 +210,7 @@ func commonFilerReadWriteTests(t *testing.T, ctx context.Context, f filer.Filer)
210210

211211
// Delete should fail for a non-empty directory.
212212
err = f.Delete(ctx, "/foo")
213-
assert.ErrorAs(t, err, &filer.DirectoryNotEmptyError{})
214-
assert.ErrorIs(t, err, fs.ErrInvalid)
213+
require.Error(t, err)
215214

216215
// Delete should succeed for a non-empty directory if the DeleteRecursively flag is set.
217216
err = f.Delete(ctx, "/foo", filer.DeleteRecursively)
@@ -645,7 +644,7 @@ func TestFilerWorkspaceFilesExtensionsDelete(t *testing.T) {
645644

646645
// Delete directory
647646
err := wf.Delete(ctx, "dir")
648-
assert.ErrorIs(t, err, fs.ErrInvalid)
647+
require.Error(t, err)
649648

650649
// Delete directory recursively
651650
err = wf.Delete(ctx, "dir", filer.DeleteRecursively)

libs/filer/dbfs_client.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -212,25 +212,6 @@ func (w *DbfsClient) Delete(ctx context.Context, name string, mode ...DeleteMode
212212
Recursive: recursive,
213213
})
214214

215-
// Return early on success.
216-
if err == nil {
217-
return nil
218-
}
219-
220-
// Special handling of this error only if it is an API error.
221-
var aerr *apierr.APIError
222-
if !errors.As(err, &aerr) {
223-
return err
224-
}
225-
226-
switch aerr.StatusCode {
227-
case http.StatusBadRequest:
228-
// Anecdotally, this error is returned when attempting to delete a non-empty directory.
229-
if aerr.ErrorCode == "IO_ERROR" {
230-
return DirectoryNotEmptyError{absPath}
231-
}
232-
}
233-
234215
return err
235216
}
236217

libs/filer/filer.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,6 @@ func (err NotAFile) Is(other error) bool {
9090
return other == fs.ErrInvalid
9191
}
9292

93-
type DirectoryNotEmptyError struct {
94-
path string
95-
}
96-
97-
func (err DirectoryNotEmptyError) Error() string {
98-
return "directory not empty: " + err.path
99-
}
100-
101-
func (err DirectoryNotEmptyError) Is(other error) bool {
102-
return other == fs.ErrInvalid
103-
}
104-
10593
type CannotDeleteRootError struct{}
10694

10795
func (err CannotDeleteRootError) Error() string {

libs/filer/files_client.go

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -246,30 +246,7 @@ func (w *FilesClient) deleteDirectory(ctx context.Context, name string) error {
246246
return CannotDeleteRootError{}
247247
}
248248

249-
err = w.workspaceClient.Files.DeleteDirectoryByDirectoryPath(ctx, absPath)
250-
251-
var aerr *apierr.APIError
252-
// Special handling of this error only if it is an API error.
253-
if !errors.As(err, &aerr) {
254-
return err
255-
}
256-
257-
// The directory delete API returns a 400 if the directory is not empty
258-
if aerr.StatusCode == http.StatusBadRequest {
259-
var reasons []string
260-
details := aerr.ErrorDetails()
261-
if details.ErrorInfo != nil {
262-
reasons = append(reasons, details.ErrorInfo.Reason)
263-
}
264-
// Error code 400 is generic and can be returned for other reasons. Make
265-
// sure one of the reasons for the error is that the directory is not empty.
266-
if !slices.Contains(reasons, "FILES_API_DIRECTORY_IS_NOT_EMPTY") {
267-
return err
268-
}
269-
return DirectoryNotEmptyError{absPath}
270-
}
271-
272-
return err
249+
return w.workspaceClient.Files.DeleteDirectoryByDirectoryPath(ctx, absPath)
273250
}
274251

275252
func (w *FilesClient) recursiveDelete(ctx context.Context, name string) error {

libs/filer/local_client.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ func (w *LocalClient) Delete(ctx context.Context, name string, mode ...DeleteMod
125125
if slices.Contains(mode, DeleteRecursively) {
126126
return os.RemoveAll(absPath)
127127
}
128-
return DirectoryNotEmptyError{path: absPath}
129128
}
130129

131130
return err

libs/filer/workspace_files_client.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,6 @@ func (w *WorkspaceFilesClient) Delete(ctx context.Context, name string, mode ...
268268
}
269269

270270
switch aerr.StatusCode {
271-
case http.StatusBadRequest:
272-
if aerr.ErrorCode == "DIRECTORY_NOT_EMPTY" {
273-
return DirectoryNotEmptyError{absPath}
274-
}
275271
case http.StatusNotFound:
276272
return FileDoesNotExistError{absPath}
277273
}

0 commit comments

Comments
 (0)