From 4098025c117225d0aa5092cb5146ce3cbf97b444 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Tue, 22 Nov 2016 01:34:57 +0100 Subject: [PATCH] Remove XL multipart tmp files when the latter is canceled (#3214) XL multipart fails to remove tmp files when an error occurs during upload, this case covers the scenario where an upload is canceled manually by the client in the middle of job. --- cmd/object-api-putobject_test.go | 4 ++++ cmd/posix.go | 6 ++++++ cmd/xl-v1-multipart.go | 5 +++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cmd/object-api-putobject_test.go b/cmd/object-api-putobject_test.go index 683da570d..ae55d5667 100644 --- a/cmd/object-api-putobject_test.go +++ b/cmd/object-api-putobject_test.go @@ -23,6 +23,7 @@ import ( "io/ioutil" "os" "path" + "runtime" "testing" ) @@ -326,6 +327,9 @@ func testObjectAPIPutObjectStaleFiles(obj ObjectLayer, instanceType string, disk // Wrapper for calling Multipart PutObject tests for both XL multiple disks and single node setup. func TestObjectAPIMultipartPutObjectStaleFiles(t *testing.T) { + if runtime.GOOS == "windows" { + return + } ExecObjectLayerStaleFilesTest(t, testObjectAPIMultipartPutObjectStaleFiles) } diff --git a/cmd/posix.go b/cmd/posix.go index b4850111d..5c8065858 100644 --- a/cmd/posix.go +++ b/cmd/posix.go @@ -944,5 +944,11 @@ func (s *posix) RenameFile(srcVolume, srcPath, dstVolume, dstPath string) (err e } return err } + + // Remove parent dir of the source file if empty + if parentDir := slashpath.Dir(preparePath(srcFilePath)); isDirEmpty(parentDir) { + deleteFile(srcVolumeDir, parentDir) + } + return nil } diff --git a/cmd/xl-v1-multipart.go b/cmd/xl-v1-multipart.go index 8ed6deee8..8fee28e61 100644 --- a/cmd/xl-v1-multipart.go +++ b/cmd/xl-v1-multipart.go @@ -394,7 +394,8 @@ func (xl xlObjects) PutObjectPart(bucket, object, uploadID string, partID int, s partSuffix := fmt.Sprintf("part.%d", partID) tmpSuffix := getUUID() - tmpPartPath := tmpSuffix + tmpPart := tmpSuffix + tmpPartPath := path.Join(tmpSuffix, partSuffix) // Initialize md5 writer. md5Writer := md5.New() @@ -424,7 +425,7 @@ func (xl xlObjects) PutObjectPart(bucket, object, uploadID string, partID int, s teeReader := io.TeeReader(lreader, mw) // Delete the temporary object part. If PutObjectPart succeeds there would be nothing to delete. - defer xl.deleteObject(minioMetaTmpBucket, tmpPartPath) + defer xl.deleteObject(minioMetaTmpBucket, tmpPart) if size > 0 { for _, disk := range onlineDisks {