mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
re-use optimized readdir for isDirEmpty() (#10829)
reduces effective memory usage by an order of magnitude, also increases performance for small objects
This commit is contained in:
parent
1a1f00fa15
commit
fde3299bf3
@ -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…
Reference in New Issue
Block a user