Browse Source

Merge pull request #1482 from hilimd/master

Fix: s3 delete object
pull/1502/head
Chris Lu 4 years ago
committed by GitHub
parent
commit
043b063136
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      weed/command/mount_std.go
  2. 6
      weed/filesys/dir.go
  3. 6
      weed/filesys/wfs.go
  4. 12
      weed/s3api/s3api_object_handlers.go

27
weed/command/mount_std.go

@ -7,7 +7,6 @@ import (
"fmt" "fmt"
"github.com/chrislusf/seaweedfs/weed/filesys/meta_cache" "github.com/chrislusf/seaweedfs/weed/filesys/meta_cache"
"os" "os"
"os/user"
"path" "path"
"runtime" "runtime"
"strconv" "strconv"
@ -87,34 +86,11 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
fuse.Unmount(dir) fuse.Unmount(dir)
uid, gid := uint32(0), uint32(0)
// detect mount folder mode // detect mount folder mode
if *option.dirAutoCreate { if *option.dirAutoCreate {
os.MkdirAll(dir, os.FileMode(0777)&^umask) os.MkdirAll(dir, os.FileMode(0777)&^umask)
} }
mountMode := os.ModeDir | 0755
fileInfo, err := os.Stat(dir) fileInfo, err := os.Stat(dir)
if err == nil {
mountMode = os.ModeDir | fileInfo.Mode()
uid, gid = util.GetFileUidGid(fileInfo)
fmt.Printf("mount point owner uid=%d gid=%d mode=%s\n", uid, gid, fileInfo.Mode())
} else {
fmt.Printf("can not stat %s\n", dir)
return false
}
if uid == 0 {
if u, err := user.Current(); err == nil {
if parsedId, pe := strconv.ParseUint(u.Uid, 10, 32); pe == nil {
uid = uint32(parsedId)
}
if parsedId, pe := strconv.ParseUint(u.Gid, 10, 32); pe == nil {
gid = uint32(parsedId)
}
fmt.Printf("current uid=%d gid=%d\n", uid, gid)
}
}
// mapping uid, gid // mapping uid, gid
uidGidMapper, err := meta_cache.NewUidGidMapper(*option.uidMap, *option.gidMap) uidGidMapper, err := meta_cache.NewUidGidMapper(*option.uidMap, *option.gidMap)
@ -174,9 +150,6 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
CacheSizeMB: *option.cacheSizeMB, CacheSizeMB: *option.cacheSizeMB,
DataCenter: *option.dataCenter, DataCenter: *option.dataCenter,
EntryCacheTtl: 3 * time.Second, EntryCacheTtl: 3 * time.Second,
MountUid: uid,
MountGid: gid,
MountMode: mountMode,
MountCtime: fileInfo.ModTime(), MountCtime: fileInfo.ModTime(),
MountMtime: time.Now(), MountMtime: time.Now(),
Umask: umask, Umask: umask,

6
weed/filesys/dir.go

@ -82,9 +82,9 @@ func (dir *Dir) Getxattr(ctx context.Context, req *fuse.GetxattrRequest, resp *f
func (dir *Dir) setRootDirAttributes(attr *fuse.Attr) { func (dir *Dir) setRootDirAttributes(attr *fuse.Attr) {
attr.Inode = 1 // filer2.FullPath(dir.Path).AsInode() attr.Inode = 1 // filer2.FullPath(dir.Path).AsInode()
attr.Valid = time.Hour attr.Valid = time.Hour
attr.Uid = dir.wfs.option.MountUid
attr.Gid = dir.wfs.option.MountGid
attr.Mode = dir.wfs.option.MountMode
attr.Uid = dir.entry.Attributes.Uid
attr.Gid = dir.entry.Attributes.Gid
attr.Mode = os.FileMode(dir.entry.Attributes.FileMode)
attr.Crtime = dir.wfs.option.MountCtime attr.Crtime = dir.wfs.option.MountCtime
attr.Ctime = dir.wfs.option.MountCtime attr.Ctime = dir.wfs.option.MountCtime
attr.Mtime = dir.wfs.option.MountMtime attr.Mtime = dir.wfs.option.MountMtime

6
weed/filesys/wfs.go

@ -37,9 +37,6 @@ type Option struct {
EntryCacheTtl time.Duration EntryCacheTtl time.Duration
Umask os.FileMode Umask os.FileMode
MountUid uint32
MountGid uint32
MountMode os.FileMode
MountCtime time.Time MountCtime time.Time
MountMtime time.Time MountMtime time.Time
@ -99,7 +96,8 @@ func NewSeaweedFileSystem(option *Option) *WFS {
wfs.metaCache.Shutdown() wfs.metaCache.Shutdown()
}) })
wfs.root = &Dir{name: wfs.option.FilerMountRootPath, wfs: wfs}
entry, _ := filer_pb.GetEntry(wfs, util.FullPath(wfs.option.FilerMountRootPath))
wfs.root = &Dir{name: wfs.option.FilerMountRootPath, wfs: wfs, entry: entry}
wfs.fsNodeCache = newFsCache(wfs.root) wfs.fsNodeCache = newFsCache(wfs.root)
return wfs return wfs

12
weed/s3api/s3api_object_handlers.go

@ -112,6 +112,12 @@ func (s3a *S3ApiServer) DeleteObjectHandler(w http.ResponseWriter, r *http.Reque
bucket, object := getBucketAndObject(r) bucket, object := getBucketAndObject(r)
response, _ := s3a.listFilerEntries(bucket, object, 1, "", "/")
if len(response.Contents) != 0 && strings.HasSuffix(object, "/") {
w.WriteHeader(http.StatusNoContent)
return
}
destUrl := fmt.Sprintf("http://%s%s/%s%s?recursive=true", destUrl := fmt.Sprintf("http://%s%s/%s%s?recursive=true",
s3a.option.Filer, s3a.option.BucketsPath, bucket, object) s3a.option.Filer, s3a.option.BucketsPath, bucket, object)
@ -121,7 +127,6 @@ func (s3a *S3ApiServer) DeleteObjectHandler(w http.ResponseWriter, r *http.Reque
} }
w.WriteHeader(http.StatusNoContent) w.WriteHeader(http.StatusNoContent)
}) })
} }
// / ObjectIdentifier carries key name for the object to delete. // / ObjectIdentifier carries key name for the object to delete.
@ -178,6 +183,11 @@ func (s3a *S3ApiServer) DeleteMultipleObjectsHandler(w http.ResponseWriter, r *h
s3a.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error { s3a.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
for _, object := range deleteObjects.Objects { for _, object := range deleteObjects.Objects {
response, _ := s3a.listFilerEntries(bucket, object.ObjectName, 1, "", "/")
if len(response.Contents) != 0 && strings.HasSuffix(object.ObjectName, "/") {
continue
}
lastSeparator := strings.LastIndex(object.ObjectName, "/") lastSeparator := strings.LastIndex(object.ObjectName, "/")
parentDirectoryPath, entryName, isDeleteData, isRecursive := "/", object.ObjectName, true, true parentDirectoryPath, entryName, isDeleteData, isRecursive := "/", object.ObjectName, true, true
if lastSeparator > 0 && lastSeparator+1 < len(object.ObjectName) { if lastSeparator > 0 && lastSeparator+1 < len(object.ObjectName) {

Loading…
Cancel
Save