You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.2 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
5 years ago
6 years ago
5 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
5 years ago
6 years ago
  1. package s3api
  2. import (
  3. "context"
  4. "fmt"
  5. "strings"
  6. "github.com/chrislusf/seaweedfs/weed/glog"
  7. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  8. )
  9. func (s3a *S3ApiServer) mkdir(parentDirectoryPath string, dirName string, fn func(entry *filer_pb.Entry)) error {
  10. return filer_pb.Mkdir(s3a, parentDirectoryPath, dirName, fn)
  11. }
  12. func (s3a *S3ApiServer) mkFile(parentDirectoryPath string, fileName string, chunks []*filer_pb.FileChunk) error {
  13. return filer_pb.MkFile(s3a, parentDirectoryPath, fileName, chunks)
  14. }
  15. func (s3a *S3ApiServer) list(parentDirectoryPath, prefix, startFrom string, inclusive bool, limit uint32) (entries []*filer_pb.Entry, err error) {
  16. err = filer_pb.List(s3a, parentDirectoryPath, prefix, func(entry *filer_pb.Entry, isLast bool) {
  17. entries = append(entries, entry)
  18. }, startFrom, inclusive, limit)
  19. return
  20. }
  21. func (s3a *S3ApiServer) rm(parentDirectoryPath, entryName string, isDeleteData, isRecursive bool) error {
  22. return s3a.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
  23. err := doDeleteEntry(client, parentDirectoryPath, entryName, isDeleteData, isRecursive)
  24. if err != nil {
  25. return err
  26. }
  27. return nil
  28. })
  29. }
  30. func doDeleteEntry(client filer_pb.SeaweedFilerClient, parentDirectoryPath string, entryName string, isDeleteData bool, isRecursive bool) error {
  31. request := &filer_pb.DeleteEntryRequest{
  32. Directory: parentDirectoryPath,
  33. Name: entryName,
  34. IsDeleteData: isDeleteData,
  35. IsRecursive: isRecursive,
  36. }
  37. glog.V(1).Infof("delete entry %v/%v: %v", parentDirectoryPath, entryName, request)
  38. if resp, err := client.DeleteEntry(context.Background(), request); err != nil {
  39. glog.V(0).Infof("delete entry %v: %v", request, err)
  40. return fmt.Errorf("delete entry %s/%s: %v", parentDirectoryPath, entryName, err)
  41. } else {
  42. if resp.Error != "" {
  43. return fmt.Errorf("delete entry %s/%s: %v", parentDirectoryPath, entryName, resp.Error)
  44. }
  45. }
  46. return nil
  47. }
  48. func (s3a *S3ApiServer) exists(parentDirectoryPath string, entryName string, isDirectory bool) (exists bool, err error) {
  49. return filer_pb.Exists(s3a, parentDirectoryPath, entryName, isDirectory)
  50. }
  51. func objectKey(key *string) *string {
  52. if strings.HasPrefix(*key, "/") {
  53. t := (*key)[1:]
  54. return &t
  55. }
  56. return key
  57. }