storage: DeleteFile should return errFileNotFound for ENOENT. (#2978)

master
Harshavardhana 8 years ago committed by GitHub
parent 0ff359ca0e
commit 8d2347bc7b
  1. 3
      cmd/object-common.go
  2. 5
      cmd/posix.go
  3. 8
      cmd/posix_test.go

@ -224,8 +224,7 @@ func cleanupDir(storage StorageAPI, volume, dirPath string) error {
delFunc = func(entryPath string) error { delFunc = func(entryPath string) error {
if !strings.HasSuffix(entryPath, slashSeparator) { if !strings.HasSuffix(entryPath, slashSeparator) {
// Delete the file entry. // Delete the file entry.
err := storage.DeleteFile(volume, entryPath) return traceError(storage.DeleteFile(volume, entryPath))
return traceError(err)
} }
// If it's a directory, list and call delFunc() for each entry. // If it's a directory, list and call delFunc() for each entry.

@ -694,6 +694,11 @@ func deleteFile(basePath, deletePath string) error {
} }
// Attempt to remove path. // Attempt to remove path.
if err := os.Remove(preparePath(deletePath)); err != nil { if err := os.Remove(preparePath(deletePath)); err != nil {
if os.IsNotExist(err) {
return errFileNotFound
} else if os.IsPermission(err) {
return errFileAccessDenied
}
return err return err
} }
// Recursively go down the next path and delete again. // Recursively go down the next path and delete again.

@ -678,8 +678,8 @@ func TestPosixListDir(t *testing.T) {
t.Errorf("Unable to initialize posix, %s", err) t.Errorf("Unable to initialize posix, %s", err)
} }
if err = posixStorage.DeleteFile("bin", "yes"); !os.IsPermission(err) { if err = posixStorage.DeleteFile("bin", "yes"); err != errFileAccessDenied {
t.Errorf("expected: Permission error, got: %s", err) t.Errorf("expected: %s, got: %s", errFileAccessDenied, err)
} }
} }
@ -792,8 +792,8 @@ func TestDeleteFile(t *testing.T) {
t.Errorf("Unable to initialize posix, %s", err) t.Errorf("Unable to initialize posix, %s", err)
} }
if err = posixStorage.DeleteFile("bin", "yes"); !os.IsPermission(err) { if err = posixStorage.DeleteFile("bin", "yes"); err != errFileAccessDenied {
t.Errorf("expected: Permission error, got: %s", err) t.Errorf("expected: %s, got: %s", errFileAccessDenied, err)
} }
} }

Loading…
Cancel
Save