From f7b6f7b22fa78ae48528f0cc4f8dd1e3bfe76a7f Mon Sep 17 00:00:00 2001 From: Nitish Tiwari Date: Fri, 17 Nov 2017 05:30:27 +0530 Subject: [PATCH] Update getObjectInfo to stat for objects with trailing / (#5179) Apache Spark sends getObject requests with trailing "/". This PR updates the getObjectInfo to stat for files even if they are sent with trailing "/". Fixes #2965 --- cmd/fs-v1.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/cmd/fs-v1.go b/cmd/fs-v1.go index 3978cdeb1..2d4974bd5 100644 --- a/cmd/fs-v1.go +++ b/cmd/fs-v1.go @@ -452,13 +452,17 @@ func (fs fsObjects) GetObject(bucket, object string, offset int64, length int64, // getObjectInfo - wrapper for reading object metadata and constructs ObjectInfo. func (fs fsObjects) getObjectInfo(bucket, object string) (oi ObjectInfo, e error) { fsMeta := fsMetaV1{} - if hasSuffix(object, slashSeparator) { - // Directory call needs to arrive with object ending with "/". - fi, err := fsStatDir(pathJoin(fs.fsPath, bucket, object)) - if err != nil { - return oi, toObjectErr(err, bucket, object) + fi, err := fsStatDir(pathJoin(fs.fsPath, bucket, object)) + if err != nil && errorCause(err) != errFileAccessDenied { + return oi, toObjectErr(err, bucket, object) + } + if fi != nil { + // If file found and request was with object ending with "/", consider it + // as directory and return object info + if hasSuffix(object, slashSeparator) { + return fsMeta.ToObjectInfo(bucket, object, fi), nil } - return fsMeta.ToObjectInfo(bucket, object, fi), nil + return oi, toObjectErr(errFileNotFound, bucket, object) } fsMetaPath := pathJoin(fs.fsPath, minioMetaBucket, bucketMetaPrefix, bucket, object, fsMetaJSONFile) @@ -485,7 +489,7 @@ func (fs fsObjects) getObjectInfo(bucket, object string) (oi ObjectInfo, e error } // Stat the file to get file size. - fi, err := fsStatFile(pathJoin(fs.fsPath, bucket, object)) + fi, err = fsStatFile(pathJoin(fs.fsPath, bucket, object)) if err != nil { return oi, toObjectErr(err, bucket, object) }