fix: log if there is readDir() failure with ListBuckets (#15461)

This is actionable and must be logged.

Bonus: also honor umask by using 0o666 for all Open() syscalls.
This commit is contained in:
Harshavardhana
2022-08-04 07:23:05 -07:00
committed by GitHub
parent 2871cb5775
commit 3bd9615d0e
6 changed files with 40 additions and 20 deletions

View File

@@ -152,12 +152,24 @@ func parseDirEnt(buf []byte) (consumed int, name []byte, typ os.FileMode, err er
// the directory itself, if the dirPath doesn't exist this function doesn't return
// an error.
func readDirFn(dirPath string, fn func(name string, typ os.FileMode) error) error {
f, err := Open(dirPath)
f, err := OpenFile(dirPath, readMode, 0o666)
if err != nil {
if osErrToFileErr(err) == errFileNotFound {
return nil
}
return osErrToFileErr(err)
if !osIsPermission(err) {
return osErrToFileErr(err)
}
// There may be permission error when dirPath
// is at the root of the disk mount that may
// not have the permissions to avoid 'noatime'
f, err = Open(dirPath)
if err != nil {
if osErrToFileErr(err) == errFileNotFound {
return nil
}
return osErrToFileErr(err)
}
}
defer f.Close()
@@ -234,12 +246,14 @@ func readDirFn(dirPath string, fn func(name string, typ os.FileMode) error) erro
func readDirWithOpts(dirPath string, opts readDirOpts) (entries []string, err error) {
f, err := OpenFile(dirPath, readMode, 0o666)
if err != nil {
if osIsPermission(err) {
f, err = Open(dirPath)
if err != nil {
return nil, osErrToFileErr(err)
}
} else {
if !osIsPermission(err) {
return nil, osErrToFileErr(err)
}
// There may be permission error when dirPath
// is at the root of the disk mount that may
// not have the permissions to avoid 'noatime'
f, err = Open(dirPath)
if err != nil {
return nil, osErrToFileErr(err)
}
}