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.

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