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.

100 lines
2.9 KiB

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