xl-storage: Do not stat bucket assuming the object exists (#11201)

In HEAD/GET, only STAT the bucket if the 
object does not exist to return the correct
error response.
master
Anis Elleuch 4 years ago committed by GitHub
parent 3e1221a01c
commit a317d220ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 40
      cmd/xl-storage.go

@ -1199,19 +1199,6 @@ func (s *xlStorage) ReadAll(ctx context.Context, volume string, path string) (bu
return nil, err return nil, err
} }
// Stat a volume entry.
_, err = os.Stat(volumeDir)
if err != nil {
if osIsNotExist(err) {
return nil, errVolumeNotFound
} else if isSysErrIO(err) {
return nil, errFaultyDisk
} else if isSysErrTooManyFiles(err) {
return nil, errTooManyOpenFiles
}
return nil, err
}
// Validate file path length, before reading. // Validate file path length, before reading.
filePath := pathJoin(volumeDir, path) filePath := pathJoin(volumeDir, path)
if err = checkPathLength(filePath); err != nil { if err = checkPathLength(filePath); err != nil {
@ -1222,6 +1209,12 @@ func (s *xlStorage) ReadAll(ctx context.Context, volume string, path string) (bu
buf, err = ioutil.ReadFile(filePath) buf, err = ioutil.ReadFile(filePath)
if err != nil { if err != nil {
if osIsNotExist(err) { if osIsNotExist(err) {
// Check if the object doesn't exist because its bucket
// is missing in order to return the correct error.
_, err = os.Stat(volumeDir)
if err != nil && osIsNotExist(err) {
return nil, errVolumeNotFound
}
return nil, errFileNotFound return nil, errFileNotFound
} else if osIsPermission(err) { } else if osIsPermission(err) {
return nil, errFileAccessDenied return nil, errFileAccessDenied
@ -1232,7 +1225,10 @@ func (s *xlStorage) ReadAll(ctx context.Context, volume string, path string) (bu
return nil, errFileNotFound return nil, errFileNotFound
} else if isSysErrIO(err) { } else if isSysErrIO(err) {
return nil, errFaultyDisk return nil, errFaultyDisk
} else if isSysErrTooManyFiles(err) {
return nil, errTooManyOpenFiles
} }
return nil, err return nil, err
} }
return buf, nil return buf, nil
@ -1465,16 +1461,6 @@ func (s *xlStorage) ReadFileStream(ctx context.Context, volume, path string, off
if err != nil { if err != nil {
return nil, err return nil, err
} }
// Stat a volume entry.
_, err = os.Stat(volumeDir)
if err != nil {
if osIsNotExist(err) {
return nil, errVolumeNotFound
} else if isSysErrIO(err) {
return nil, errFaultyDisk
}
return nil, err
}
// Validate effective path length before reading. // Validate effective path length before reading.
filePath := pathJoin(volumeDir, path) filePath := pathJoin(volumeDir, path)
@ -1487,6 +1473,10 @@ func (s *xlStorage) ReadFileStream(ctx context.Context, volume, path string, off
if err != nil { if err != nil {
switch { switch {
case osIsNotExist(err): case osIsNotExist(err):
_, err = os.Stat(volumeDir)
if err != nil && osIsNotExist(err) {
return nil, errVolumeNotFound
}
return nil, errFileNotFound return nil, errFileNotFound
case osIsPermission(err): case osIsPermission(err):
return nil, errFileAccessDenied return nil, errFileAccessDenied
@ -1510,6 +1500,10 @@ func (s *xlStorage) ReadFileStream(ctx context.Context, volume, path string, off
if err != nil { if err != nil {
switch { switch {
case osIsNotExist(err): case osIsNotExist(err):
_, err = os.Stat(volumeDir)
if err != nil && osIsNotExist(err) {
return nil, errVolumeNotFound
}
return nil, errFileNotFound return nil, errFileNotFound
case osIsPermission(err): case osIsPermission(err):
return nil, errFileAccessDenied return nil, errFileAccessDenied

Loading…
Cancel
Save