diff options
| author | Chris Lu <chris.lu@gmail.com> | 2018-09-04 00:42:44 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2018-09-04 00:42:44 -0700 |
| commit | ce6a2140a2173ec4090a18d07b85e8c553bcb3a8 (patch) | |
| tree | c1fe7bc40171caed9c951076cb679ae821c0abd7 /weed/s3api/filer_util.go | |
| parent | 7f760f16b0d2f55e92c5d57ca2167edbc257cf54 (diff) | |
| download | seaweedfs-ce6a2140a2173ec4090a18d07b85e8c553bcb3a8.tar.xz seaweedfs-ce6a2140a2173ec4090a18d07b85e8c553bcb3a8.zip | |
preparing to support S3 multipart uploads
Diffstat (limited to 'weed/s3api/filer_util.go')
| -rw-r--r-- | weed/s3api/filer_util.go | 55 |
1 files changed, 43 insertions, 12 deletions
diff --git a/weed/s3api/filer_util.go b/weed/s3api/filer_util.go index be807fb82..a44305505 100644 --- a/weed/s3api/filer_util.go +++ b/weed/s3api/filer_util.go @@ -10,22 +10,28 @@ import ( "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" ) -func (s3a *S3ApiServer) mkdir(parentDirectoryPath string, dirName string) error { +func (s3a *S3ApiServer) mkdir(parentDirectoryPath string, dirName string, fn func(entry *filer_pb.Entry)) error { return s3a.withFilerClient(func(client filer_pb.SeaweedFilerClient) error { + entry := &filer_pb.Entry{ + Name: dirName, + IsDirectory: true, + Attributes: &filer_pb.FuseAttributes{ + Mtime: time.Now().Unix(), + Crtime: time.Now().Unix(), + FileMode: uint32(0777 | os.ModeDir), + Uid: OS_UID, + Gid: OS_GID, + }, + } + + if fn != nil { + fn(entry) + } + request := &filer_pb.CreateEntryRequest{ Directory: parentDirectoryPath, - Entry: &filer_pb.Entry{ - Name: dirName, - IsDirectory: true, - Attributes: &filer_pb.FuseAttributes{ - Mtime: time.Now().Unix(), - Crtime: time.Now().Unix(), - FileMode: uint32(0777 | os.ModeDir), - Uid: OS_UID, - Gid: OS_GID, - }, - }, + Entry: entry, } glog.V(1).Infof("create bucket: %v", request) @@ -83,3 +89,28 @@ func (s3a *S3ApiServer) rm(parentDirectoryPath string, entryName string, isDirec }) } + +func (s3a *S3ApiServer) exists(parentDirectoryPath string, entryName string, isDirectory bool) (exists bool, err error) { + + err = s3a.withFilerClient(func(client filer_pb.SeaweedFilerClient) error { + + ctx := context.Background() + + request := &filer_pb.LookupDirectoryEntryRequest{ + Directory: parentDirectoryPath, + Name: entryName, + } + + glog.V(1).Infof("delete entry %v/%v: %v", parentDirectoryPath, entryName, request) + resp, err := client.LookupDirectoryEntry(ctx, request) + if err != nil { + return fmt.Errorf("delete entry %s/%s: %v", parentDirectoryPath, entryName, err) + } + + exists = resp.Entry.IsDirectory == isDirectory + + return nil + }) + + return +} |
