xl: Avoid removing directory content in Delete API (#5548)

Delete & Multi Delete API should not try to remove the directory content.
The only permitted case is with zero size object with a trailing slash
in its name.
This commit is contained in:
Anis Elleuch
2018-02-21 00:33:26 +01:00
committed by kannappanr
parent db9e83de62
commit d2d49f6c6c
2 changed files with 22 additions and 7 deletions

View File

@@ -24,6 +24,7 @@ import (
slashpath "path"
"path/filepath"
"runtime"
"strings"
"sync"
"sync/atomic"
"syscall"
@@ -860,9 +861,13 @@ func deleteFile(basePath, deletePath string) error {
return err
}
// Recursively go down the next path and delete again.
// Errors for parent directories shouldn't trickle down.
deleteFile(basePath, slashpath.Dir(deletePath))
// Trailing slash is removed when found to ensure
// slashpath.Dir() to work as intended.
deletePath = strings.TrimSuffix(deletePath, slashSeparator)
deletePath = slashpath.Dir(deletePath)
// Delete parent directory. Errors for parent directories shouldn't trickle down.
deleteFile(basePath, deletePath)
return nil
}