diff --git a/cmd/posix.go b/cmd/posix.go index b777a1b3e..7db081fae 100644 --- a/cmd/posix.go +++ b/cmd/posix.go @@ -912,7 +912,10 @@ func deleteFile(basePath, deletePath string) error { } // Recursively go down the next path and delete again. - return deleteFile(basePath, slashpath.Dir(deletePath)) + // Errors for parent directories shouldn't trickle down. + deleteFile(basePath, slashpath.Dir(deletePath)) + + return nil } // DeleteFile - delete a file at path. diff --git a/cmd/posix_test.go b/cmd/posix_test.go index d5d48c70d..27817afb2 100644 --- a/cmd/posix_test.go +++ b/cmd/posix_test.go @@ -742,6 +742,17 @@ func TestPosixDeleteFile(t *testing.T) { t.Fatalf("Unable to create file, %s", err) } + if err = posixStorage.MakeVol("no-permissions"); err != nil { + t.Fatalf("Unable to create volume, %s", err.Error()) + } + if err = posixStorage.AppendFile("no-permissions", "dir/file", []byte("Hello, world")); err != nil { + t.Fatalf("Unable to create file, %s", err.Error()) + } + // Parent directory must have write permissions, this is read + execute. + if err = os.Chmod(pathJoin(path, "no-permissions"), 0555); err != nil { + t.Fatalf("Unable to chmod directory, %s", err.Error()) + } + testCases := []struct { srcVol string srcPath string @@ -796,6 +807,15 @@ func TestPosixDeleteFile(t *testing.T) { ioErrCnt: 0, expectedErr: errFileNameTooLong, }, + // TestPosix case - 7. + // TestPosix case with undeletable parent directory. + // File can delete, dir cannot delete because no-permissions doesn't have write perms. + { + srcVol: "no-permissions", + srcPath: "dir/file", + ioErrCnt: 0, + expectedErr: nil, + }, } for i, testCase := range testCases {