backports from main

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2022-11-19 13:07:03 +01:00
parent 0fa08ddbaa
commit 0a8edcd811
18 changed files with 170 additions and 103 deletions

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,8 +163,10 @@ func (fs *S3Fs) Stat(name string) (os.FileInfo, error) {
}
obj, err := fs.headObject(name)
if err == nil {
// a "dir" has a trailing "/" so we cannot have a directory here
return updateFileInfoModTime(fs.getStorageID(), name, NewFileInfo(name, false, obj.ContentLength,
// 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))
}
if !fs.IsNotExist(err) {