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.

84 lines
2.3 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
6 years ago
5 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, isLast bool, err error) {
  16. err = filer_pb.List(s3a, parentDirectoryPath, prefix, func(entry *filer_pb.Entry, isLastEntry bool) error {
  17. entries = append(entries, entry)
  18. if isLastEntry {
  19. isLast = true
  20. }
  21. return nil
  22. }, startFrom, inclusive, limit)
  23. return
  24. }
  25. func (s3a *S3ApiServer) rm(parentDirectoryPath, entryName string, isDeleteData, isRecursive bool) error {
  26. return s3a.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
  27. err := doDeleteEntry(client, parentDirectoryPath, entryName, isDeleteData, isRecursive)
  28. if err != nil {
  29. return err
  30. }
  31. return nil
  32. })
  33. }
  34. func doDeleteEntry(client filer_pb.SeaweedFilerClient, parentDirectoryPath string, entryName string, isDeleteData bool, isRecursive bool) error {
  35. request := &filer_pb.DeleteEntryRequest{
  36. Directory: parentDirectoryPath,
  37. Name: entryName,
  38. IsDeleteData: isDeleteData,
  39. IsRecursive: isRecursive,
  40. }
  41. glog.V(1).Infof("delete entry %v/%v: %v", parentDirectoryPath, entryName, request)
  42. if resp, err := client.DeleteEntry(context.Background(), request); err != nil {
  43. glog.V(0).Infof("delete entry %v: %v", request, err)
  44. return fmt.Errorf("delete entry %s/%s: %v", parentDirectoryPath, entryName, err)
  45. } else {
  46. if resp.Error != "" {
  47. return fmt.Errorf("delete entry %s/%s: %v", parentDirectoryPath, entryName, resp.Error)
  48. }
  49. }
  50. return nil
  51. }
  52. func (s3a *S3ApiServer) exists(parentDirectoryPath string, entryName string, isDirectory bool) (exists bool, err error) {
  53. return filer_pb.Exists(s3a, parentDirectoryPath, entryName, isDirectory)
  54. }
  55. func objectKey(key *string) *string {
  56. if strings.HasPrefix(*key, "/") {
  57. t := (*key)[1:]
  58. return &t
  59. }
  60. return key
  61. }