From 1cd7f1e38dcbcfff14b076265669074c1fa3464c Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 30 May 2023 09:56:50 -0700 Subject: [PATCH] fix: cleanup empty multipart folders upon stale upload cleanup (#17312) --- cmd/erasure-multipart.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/cmd/erasure-multipart.go b/cmd/erasure-multipart.go index 8cca0dc6e..b940673a3 100644 --- a/cmd/erasure-multipart.go +++ b/cmd/erasure-multipart.go @@ -198,7 +198,7 @@ func (er erasureObjects) cleanupStaleUploadsOnDisk(ctx context.Context, disk Sto diskPath := disk.Endpoint().Path readDirFn(pathJoin(diskPath, minioMetaMultipartBucket), func(shaDir string, typ os.FileMode) error { - return readDirFn(pathJoin(diskPath, minioMetaMultipartBucket, shaDir), func(uploadIDDir string, typ os.FileMode) error { + readDirFn(pathJoin(diskPath, minioMetaMultipartBucket, shaDir), func(uploadIDDir string, typ os.FileMode) error { uploadIDPath := pathJoin(shaDir, uploadIDDir) fi, err := disk.ReadVersion(ctx, minioMetaMultipartBucket, uploadIDPath, "", false) if err != nil { @@ -209,19 +209,20 @@ func (er erasureObjects) cleanupStaleUploadsOnDisk(ctx context.Context, disk Sto removeAll(pathJoin(diskPath, minioMetaMultipartBucket, uploadIDPath)) } wait() - vi, err := disk.StatVol(ctx, pathJoin(minioMetaMultipartBucket, shaDir)) - if err != nil { - return nil - } - wait = deletedCleanupSleeper.Timer(ctx) - if now.Sub(vi.Created) > expiry { - // We are not deleting shaDir recursively here, if shaDir is empty - // and its older then we can happily delete it. - Remove(pathJoin(diskPath, minioMetaMultipartBucket, shaDir)) - } - wait() return nil }) + vi, err := disk.StatVol(ctx, pathJoin(minioMetaMultipartBucket, shaDir)) + if err != nil { + return nil + } + wait := deletedCleanupSleeper.Timer(ctx) + if now.Sub(vi.Created) > expiry { + // We are not deleting shaDir recursively here, if shaDir is empty + // and its older then we can happily delete it. + Remove(pathJoin(diskPath, minioMetaMultipartBucket, shaDir)) + } + wait() + return nil }) readDirFn(pathJoin(diskPath, minioMetaTmpBucket), func(tmpDir string, typ os.FileMode) error {