check more mime types for SeaweedFS dirs

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino 2022-11-16 21:38:27 +01:00
parent 6591769a07
commit 67de4c9c07
No known key found for this signature in database
GPG key ID: 935D2952DEC4EECF

View file

@ -60,6 +60,10 @@ const (
s3fsName = "S3Fs"
)
var (
s3DirMimeTypes = []string{s3DirMimeType, "httpd/unix-directory"}
)
// S3Fs is a Fs implementation for AWS S3 compatible object storages
type S3Fs struct {
connectionID string
@ -159,9 +163,9 @@ func (fs *S3Fs) Stat(name string) (os.FileInfo, error) {
}
obj, err := fs.headObject(name)
if err == nil {
// Some s3 providers (like seaweedfs) do not support traling '/' in object key.
// So We have to check Content-type of the object and detect that the object whether is an empty directory or an ordinary object.
isDir := util.GetStringFromPointer(obj.ContentType) == s3DirMimeType
// 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))
return updateFileInfoModTime(fs.getStorageID(), name, NewFileInfo(name, isDir, obj.ContentLength,
util.GetTimeFromPointer(obj.LastModified), false))
}