From 926e480156600cf3a99743645cc711fc5504f64a Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Tue, 20 Feb 2018 21:20:18 +0100 Subject: [PATCH] posix.RenameFile(): Allow overwriting an empty directory (#5551) Overwriting files is allowed, but since the introduction of the object directory, we will aslo need to allow overwriting an empty directory. Putting twice the same object directory won't fail with 403 error anymore. --- cmd/posix.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/cmd/posix.go b/cmd/posix.go index 94aad59c1..04e0a10ee 100644 --- a/cmd/posix.go +++ b/cmd/posix.go @@ -932,14 +932,14 @@ func (s *posix) RenameFile(srcVolume, srcPath, dstVolume, dstPath string) (err e return err } // Stat a volume entry. - _, err = os.Stat((srcVolumeDir)) + _, err = os.Stat(srcVolumeDir) if err != nil { if os.IsNotExist(err) { return errVolumeNotFound } return err } - _, err = os.Stat((dstVolumeDir)) + _, err = os.Stat(dstVolumeDir) if err != nil { if os.IsNotExist(err) { return errVolumeNotFound @@ -953,23 +953,24 @@ func (s *posix) RenameFile(srcVolume, srcPath, dstVolume, dstPath string) (err e return errFileAccessDenied } srcFilePath := slashpath.Join(srcVolumeDir, srcPath) - if err = checkPathLength((srcFilePath)); err != nil { + if err = checkPathLength(srcFilePath); err != nil { return err } dstFilePath := slashpath.Join(dstVolumeDir, dstPath) - if err = checkPathLength((dstFilePath)); err != nil { + if err = checkPathLength(dstFilePath); err != nil { return err } if srcIsDir { - // If source is a directory we expect the destination to be non-existent always. - _, err = os.Stat((dstFilePath)) - if err == nil { + // If source is a directory, we expect the destination to be non-existent but we + // we still need to allow overwriting an empty directory since it represents + // an object empty directory. + _, err = os.Stat(dstFilePath) + if err == nil && !isDirEmpty(dstFilePath) { return errFileAccessDenied } if !os.IsNotExist(err) { return err } - // Destination does not exist, hence proceed with the rename. } if err = renameAll(srcFilePath, dstFilePath); err != nil {