diff options
| author | Chris Lu <chris.lu@gmail.com> | 2018-09-03 13:03:16 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2018-09-03 13:03:16 -0700 |
| commit | 03f852c799219b94b7cdf9fc48abce0b36a5a14a (patch) | |
| tree | bdc0179b4f1bab1a3c1921c41abf04e1323ec88f /weed/s3api/filer_util.go | |
| parent | 0b0ece964915691cd3146e1457c471df3fcf6470 (diff) | |
| download | seaweedfs-03f852c799219b94b7cdf9fc48abce0b36a5a14a.tar.xz seaweedfs-03f852c799219b94b7cdf9fc48abce0b36a5a14a.zip | |
refactoring
Diffstat (limited to 'weed/s3api/filer_util.go')
| -rw-r--r-- | weed/s3api/filer_util.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/weed/s3api/filer_util.go b/weed/s3api/filer_util.go new file mode 100644 index 000000000..aa0a14b80 --- /dev/null +++ b/weed/s3api/filer_util.go @@ -0,0 +1,60 @@ +package s3api + +import ( + "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" + "time" + "os" + "fmt" + "github.com/chrislusf/glog" + "context" +) + +func (s3a *S3ApiServer) mkdir(parentDirectoryPath string, dirName string) error { + return s3a.withFilerClient(func(client filer_pb.SeaweedFilerClient) error { + + 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, + }, + }, + } + + glog.V(1).Infof("create bucket: %v", request) + if _, err := client.CreateEntry(context.Background(), request); err != nil { + return fmt.Errorf("mkdir %s/%s: %v", parentDirectoryPath, dirName, err) + } + + return nil + }) +} + +func (s3a *S3ApiServer) list(parentDirectoryPath string) (entries []*filer_pb.Entry, err error) { + + s3a.withFilerClient(func(client filer_pb.SeaweedFilerClient) error { + + request := &filer_pb.ListEntriesRequest{ + Directory: s3a.option.BucketsPath, + } + + glog.V(4).Infof("read directory: %v", request) + resp, err := client.ListEntries(context.Background(), request) + if err != nil { + return fmt.Errorf("list dir %v: %v", parentDirectoryPath, err) + } + + entries = resp.Entries + + return nil + }) + + return + +} |
