瀏覽代碼

check more mime types for SeaweedFS dirs

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
Nicola Murino 2 年之前
父節點
當前提交
67de4c9c07
共有 1 個文件被更改,包括 7 次插入3 次删除
  1. 7 3
      internal/vfs/s3fs.go

+ 7 - 3
internal/vfs/s3fs.go

@@ -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))
 	}