mirror of
https://github.com/minio/minio.git
synced 2024-12-25 06:35:56 -05:00
fix: nLink is unreliable on all filesystems (#19187)
ext4, xfs support this behavior however btrfs, nfs may not support it properly. in-case when we see Nlink < 2 then we know that we need to fallback on readdir() fixes a regression from #19100 fixes #19181
This commit is contained in:
parent
9a4d003ac7
commit
e385f54185
@ -20,7 +20,9 @@
|
|||||||
|
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import "syscall"
|
import (
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
// Returns true if no error and there is no object or prefix inside this directory
|
// Returns true if no error and there is no object or prefix inside this directory
|
||||||
func isDirEmpty(dirname string) bool {
|
func isDirEmpty(dirname string) bool {
|
||||||
@ -28,5 +30,17 @@ func isDirEmpty(dirname string) bool {
|
|||||||
if err := syscall.Stat(dirname, &stat); err != nil {
|
if err := syscall.Stat(dirname, &stat); err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return stat.Mode&syscall.S_IFMT == syscall.S_IFDIR && stat.Nlink < 3
|
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 {
|
||||||
|
entries, err := readDirN(dirname, 1)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return len(entries) == 0
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user