fs: Avoid non-idempotent code flow in ListBuckets() (#4798)

Under the call flow

```
Readdir
   +
   |
   |
   | path-entry
   |
   |
   v
StatDir
```

Existing code was written in a manner where say
a bucket/top-level directory was indeed deleted
between Readdir() and before StatDir() we would
ignore certain errors. This is not a plausible
situation and might not happen in almost all
practical cases. We do not have to look for
or interpret these errors returned by StatDir()
instead we can just collect the successful
values and return back to the client. We do not
need to pre-maturely decide on bucket access
we just let filesystem decide subsequently for
real I/O operations.

Refer #4658
master
Harshavardhana 7 years ago committed by Dee Koder
parent 3ff09b9b72
commit e7cdd8f02c
  1. 13
      cmd/fs-v1.go

@ -257,17 +257,14 @@ func (fs fsObjects) ListBuckets() ([]BucketInfo, error) {
}
var fi os.FileInfo
fi, err = fsStatDir(pathJoin(fs.fsPath, entry))
// There seems like no practical reason to check for errors
// at this point, if there are indeed errors we can simply
// just ignore such buckets and list only those which
// return proper Stat information instead.
if err != nil {
// If the directory does not exist, skip the entry.
if errorCause(err) == errVolumeNotFound {
// Ignore any errors returned here.
continue
} else if errorCause(err) == errVolumeAccessDenied {
// Skip the entry if its a file.
continue
}
return nil, err
}
bucketInfos = append(bucketInfos, BucketInfo{
Name: fi.Name(),
// As osStat() doesnt carry CreatedTime, use ModTime() as CreatedTime.

Loading…
Cancel
Save