avoid double deletes() when no more versions (#16206)

This commit is contained in:
Harshavardhana 2022-12-12 01:40:04 -08:00 committed by GitHub
parent c233c8e329
commit 20ef5e7a6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1118,6 +1118,7 @@ func (s *xlStorage) DeleteVersion(ctx context.Context, volume, path string, fi F
}
if len(xlMeta.versions) != 0 {
// xl.meta must still exist for other versions, dataDir is purged.
buf, err = xlMeta.AppendTo(metaDataPoolGet())
defer metaDataPoolPut(buf)
if err != nil {
@ -1127,17 +1128,13 @@ func (s *xlStorage) DeleteVersion(ctx context.Context, volume, path string, fi F
return s.WriteAll(ctx, volume, pathJoin(path, xlStorageFormatFile), buf)
}
// Move xl.meta to trash
filePath := pathJoin(volumeDir, path, xlStorageFormatFile)
// No more versions, this is the last version purge everything.
filePath := pathJoin(volumeDir, path)
if err = checkPathLength(filePath); err != nil {
return err
}
err = s.moveToTrash(filePath, false, false)
if err == nil || err == errFileNotFound {
s.deleteFile(volumeDir, pathJoin(volumeDir, path), false, false)
}
return err
return s.deleteFile(volumeDir, filePath, true, false)
}
// Updates only metadata for a given version.