In HDFS gateway fix non-empty folder behavior (#8254)

To be compatible with our FS and Erasure coded
mode deployments, make sure that we do not send
200 OK for folders which have files inside.

Fixes #8143
master
Harshavardhana 5 years ago committed by kannappanr
parent dfa1b417a8
commit cb01516a26
  1. 3
      .travis.yml
  2. 24
      cmd/gateway/hdfs/gateway-hdfs.go

@ -56,6 +56,3 @@ before_script:
before_install: before_install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then nvm install 11.10.1 ; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then nvm install 11.10.1 ; fi
after_success:
- bash <(curl -s https://codecov.io/bash)

@ -507,12 +507,34 @@ func (n *hdfsObjects) GetObject(ctx context.Context, bucket, key string, startOf
return hdfsToObjectErr(ctx, err, bucket, key) return hdfsToObjectErr(ctx, err, bucket, key)
} }
func (n *hdfsObjects) isObjectDir(ctx context.Context, bucket, object string) bool {
f, err := n.clnt.Open(minio.PathJoin(hdfsSeparator, bucket, object))
if err != nil {
if os.IsNotExist(err) {
return false
}
logger.LogIf(ctx, err)
return false
}
defer f.Close()
fis, err := f.Readdir(1)
if err != nil {
logger.LogIf(ctx, err)
return false
}
return len(fis) == 0
}
// GetObjectInfo reads object info and replies back ObjectInfo. // GetObjectInfo reads object info and replies back ObjectInfo.
func (n *hdfsObjects) GetObjectInfo(ctx context.Context, bucket, object string, opts minio.ObjectOptions) (objInfo minio.ObjectInfo, err error) { func (n *hdfsObjects) GetObjectInfo(ctx context.Context, bucket, object string, opts minio.ObjectOptions) (objInfo minio.ObjectInfo, err error) {
_, err = n.clnt.Stat(minio.PathJoin(hdfsSeparator, bucket)) _, err = n.clnt.Stat(minio.PathJoin(hdfsSeparator, bucket))
if err != nil { if err != nil {
return objInfo, hdfsToObjectErr(ctx, err, bucket) return objInfo, hdfsToObjectErr(ctx, err, bucket)
} }
if strings.HasSuffix(object, hdfsSeparator) && !n.isObjectDir(ctx, bucket, object) {
return objInfo, hdfsToObjectErr(ctx, os.ErrNotExist, bucket, object)
}
fi, err := n.clnt.Stat(minio.PathJoin(hdfsSeparator, bucket, object)) fi, err := n.clnt.Stat(minio.PathJoin(hdfsSeparator, bucket, object))
if err != nil { if err != nil {
return objInfo, hdfsToObjectErr(ctx, err, bucket, object) return objInfo, hdfsToObjectErr(ctx, err, bucket, object)
@ -536,7 +558,7 @@ func (n *hdfsObjects) PutObject(ctx context.Context, bucket string, object strin
name := minio.PathJoin(hdfsSeparator, bucket, object) name := minio.PathJoin(hdfsSeparator, bucket, object)
// If its a directory create a prefix { // If its a directory create a prefix {
if strings.HasSuffix(object, hdfsSeparator) { if strings.HasSuffix(object, hdfsSeparator) && r.Size() == 0 {
if err = n.clnt.MkdirAll(name, os.FileMode(0755)); err != nil { if err = n.clnt.MkdirAll(name, os.FileMode(0755)); err != nil {
n.deleteObject(minio.PathJoin(hdfsSeparator, bucket), name) n.deleteObject(minio.PathJoin(hdfsSeparator, bucket), name)
return objInfo, hdfsToObjectErr(ctx, err, bucket, object) return objInfo, hdfsToObjectErr(ctx, err, bucket, object)

Loading…
Cancel
Save