From ac91170d6596a9981c2c413231f9e11ead05423b Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Tue, 13 Dec 2022 08:55:01 +0100 Subject: [PATCH] S3: improve "directories" detection Fixes #1097 Signed-off-by: Nicola Murino --- internal/vfs/s3fs.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/vfs/s3fs.go b/internal/vfs/s3fs.go index 9242ca8a..0f82d67f 100644 --- a/internal/vfs/s3fs.go +++ b/internal/vfs/s3fs.go @@ -165,6 +165,10 @@ func (fs *S3Fs) Stat(name string) (os.FileInfo, error) { // Some S3 providers (like SeaweedFS) remove the trailing '/' from object keys. // So we check some common content types to detect if this is a "directory". isDir := util.Contains(s3DirMimeTypes, util.GetStringFromPointer(obj.ContentType)) + if obj.ContentLength == 0 && !isDir { + _, err = fs.headObject(name + "/") + isDir = err == nil + } return updateFileInfoModTime(fs.getStorageID(), name, NewFileInfo(name, isDir, obj.ContentLength, util.GetTimeFromPointer(obj.LastModified), false)) }