mirror of
https://github.com/minio/minio.git
synced 2025-11-22 18:47:43 -05:00
posix: test isDirEmpty, change error conditional (#4743)
This commit adds a new test for isDirEmpty (for code coverage) and changes around the error conditional. Previously, there was a `return nil` statement that would only be triggered under a race condition and would trip up our test coverage for no real reason. With this new error conditional, there's no awkward 'else'-esque condition, which means test coverage will not change between runs for no reason in this specific test. It's also a cleaner read.
This commit is contained in:
committed by
Dee Koder
parent
fcc61fa46a
commit
28bc5899fd
20
cmd/posix.go
20
cmd/posix.go
@@ -74,24 +74,20 @@ func checkPathLength(pathName string) error {
|
||||
func isDirEmpty(dirname string) bool {
|
||||
f, err := os.Open(preparePath(dirname))
|
||||
if err != nil {
|
||||
errorIf(func() error {
|
||||
if !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(), "Unable to access directory.")
|
||||
if !os.IsNotExist(err) {
|
||||
errorIf(err, "Unable to access directory")
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
defer f.Close()
|
||||
// List one entry.
|
||||
_, err = f.Readdirnames(1)
|
||||
if err != io.EOF {
|
||||
errorIf(func() error {
|
||||
if !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(), "Unable to list directory.")
|
||||
if !os.IsNotExist(err) {
|
||||
errorIf(err, "Unable to list directory")
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
// Returns true if we have reached EOF, directory is indeed empty.
|
||||
|
||||
Reference in New Issue
Block a user