init: Cleanup .minio/tmp directories recursively. Also takes care of cleaning up of parts directory during abortMultipartUpload. (#1532)

This commit is contained in:
Krishna Srinivas
2016-05-08 22:45:34 +05:30
committed by Harshavardhana
parent 3f51dd4fd4
commit a205aca6d2
4 changed files with 41 additions and 22 deletions
+30 -1
View File
@@ -38,13 +38,42 @@ func initObjectLayer(storage StorageAPI) error {
}
}
// Cleanup all temp entries upon start.
err := cleanupAllTmpEntries(storage)
err := cleanupDir(storage, minioMetaBucket, tmpMetaPrefix)
if err != nil {
return toObjectErr(err, minioMetaBucket, tmpMetaPrefix)
}
return nil
}
// Cleanup a directory recursively.
func cleanupDir(storage StorageAPI, volume, dirPath string) error {
var delFunc func(string) error
// Function to delete entries recursively.
delFunc = func(entryPath string) error {
if !strings.HasSuffix(entryPath, slashSeparator) {
// No trailing "/" means that this is a file which can be deleted.
return storage.DeleteFile(volume, entryPath)
}
// If it's a directory, list and call delFunc() for each entry.
entries, err := storage.ListDir(volume, entryPath)
if err != nil {
if err == errFileNotFound {
// if dirPath prefix never existed.
return nil
}
return err
}
for _, entry := range entries {
err = delFunc(pathJoin(entryPath, entry))
if err != nil {
return err
}
}
return nil
}
return delFunc(retainSlash(dirPath))
}
/// Common object layer functions.
// makeBucket - create a bucket, is a common function for both object layers.