Skip to content

Commit

Permalink
re-use optimized readdir for isDirEmpty() (#10829)
Browse files Browse the repository at this point in the history
reduces effective memory usage by an order
of magnitude, also increases performance for
small objects
  • Loading branch information
harshavardhana committed Nov 4, 2020
1 parent 1a1f00f commit fde3299
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions cmd/xl-storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,24 +219,14 @@ func getValidPath(path string, requireDirectIO bool) (string, error) {

// isDirEmpty - returns whether given directory is empty or not.
func isDirEmpty(dirname string) bool {
f, err := os.Open(dirname)
entries, err := readDirN(dirname, 1)
if err != nil {
if !os.IsNotExist(err) {
logger.LogIf(GlobalContext, err)
}

return false
}
defer f.Close()
// List one entry.
if _, err = f.Readdirnames(1); err != io.EOF {
if !os.IsNotExist(err) {
if err != errFileNotFound {
logger.LogIf(GlobalContext, err)
}
return false
}
// Returns true if we have reached EOF, directory is indeed empty.
return true
return len(entries) == 0
}

// Initialize a new storage disk.
Expand Down

0 comments on commit fde3299

Please sign in to comment.