turn-off Nlink readdir() optimization for NFS/CIFS (#19420)

fixes #19418
fixes #19416
This commit is contained in:
Harshavardhana
2024-04-05 08:17:08 -07:00
committed by GitHub
parent 96d226c0b1
commit a207bd6790
5 changed files with 28 additions and 21 deletions
+9 -12
View File
@@ -25,22 +25,19 @@ import (
)
// Returns true if no error and there is no object or prefix inside this directory
func isDirEmpty(dirname string) bool {
var stat syscall.Stat_t
if err := syscall.Stat(dirname, &stat); err != nil {
return false
}
if stat.Mode&syscall.S_IFMT == syscall.S_IFDIR && stat.Nlink == 2 {
return true
}
// On filesystems such as btrfs, nfs this is not true, so fallback
// to performing readdir() instead.
if stat.Mode&syscall.S_IFMT == syscall.S_IFDIR && stat.Nlink < 2 {
func isDirEmpty(dirname string, legacy bool) bool {
if legacy {
// On filesystems such as btrfs, nfs this is not true, so fallback
// to performing readdir() instead.
entries, err := readDirN(dirname, 1)
if err != nil {
return false
}
return len(entries) == 0
}
return false
var stat syscall.Stat_t
if err := syscall.Stat(dirname, &stat); err != nil {
return false
}
return stat.Mode&syscall.S_IFMT == syscall.S_IFDIR && stat.Nlink == 2
}