|
|
@ -73,22 +73,28 @@ func checkPathLength(pathName string) error { |
|
|
|
func isDirEmpty(dirname string) bool { |
|
|
|
func isDirEmpty(dirname string) bool { |
|
|
|
f, err := os.Open(dirname) |
|
|
|
f, err := os.Open(dirname) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
errorIf(err, "Unable to access directory.") |
|
|
|
errorIf(func() error { |
|
|
|
|
|
|
|
if !os.IsNotExist(err) { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
}(), "Unable to access directory.") |
|
|
|
return false |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
defer f.Close() |
|
|
|
defer f.Close() |
|
|
|
// List one entry.
|
|
|
|
// List one entry.
|
|
|
|
_, err = f.Readdirnames(1) |
|
|
|
_, err = f.Readdirnames(1) |
|
|
|
if err != nil { |
|
|
|
if err != io.EOF { |
|
|
|
if err == io.EOF { |
|
|
|
errorIf(func() error { |
|
|
|
// Returns true if we have reached EOF, directory is indeed empty.
|
|
|
|
if !os.IsNotExist(err) { |
|
|
|
return true |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
errorIf(err, "Unable to list directory.") |
|
|
|
return nil |
|
|
|
|
|
|
|
}(), "Unable to list directory.") |
|
|
|
return false |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
// Directory is not empty.
|
|
|
|
// Returns true if we have reached EOF, directory is indeed empty.
|
|
|
|
return false |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Initialize a new storage disk.
|
|
|
|
// Initialize a new storage disk.
|
|
|
|