re-use optimized readdir for isDirEmpty() (#10829)

reduces effective memory usage by an order
of magnitude, also increases performance for
small objects
master
Harshavardhana 4 years ago committed by GitHub
parent 1a1f00fa15
commit fde3299bf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      cmd/xl-storage.go

@ -219,24 +219,14 @@ func getValidPath(path string, requireDirectIO bool) (string, error) {
// isDirEmpty - returns whether given directory is empty or not. // isDirEmpty - returns whether given directory is empty or not.
func isDirEmpty(dirname string) bool { func isDirEmpty(dirname string) bool {
f, err := os.Open(dirname) entries, err := readDirN(dirname, 1)
if err != nil { if err != nil {
if !os.IsNotExist(err) { if err != errFileNotFound {
logger.LogIf(GlobalContext, err)
}
return false
}
defer f.Close()
// List one entry.
if _, err = f.Readdirnames(1); err != io.EOF {
if !os.IsNotExist(err) {
logger.LogIf(GlobalContext, err) logger.LogIf(GlobalContext, err)
} }
return false return false
} }
// Returns true if we have reached EOF, directory is indeed empty. return len(entries) == 0
return true
} }
// Initialize a new storage disk. // Initialize a new storage disk.

Loading…
Cancel
Save