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.

103 lines
2.6 KiB

3 years ago
3 years ago
3 years ago
3 years ago
  1. package mount
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/chrislusf/seaweedfs/weed/filer"
  6. "github.com/chrislusf/seaweedfs/weed/glog"
  7. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  8. "github.com/hanwen/go-fuse/v2/fuse"
  9. "os"
  10. "strings"
  11. "syscall"
  12. "time"
  13. )
  14. func (wfs *WFS) Mkdir(cancel <-chan struct{}, in *fuse.MkdirIn, name string, out *fuse.EntryOut) (code fuse.Status) {
  15. if s := checkName(name); s != fuse.OK {
  16. return s
  17. }
  18. newEntry := &filer_pb.Entry{
  19. Name: name,
  20. IsDirectory: true,
  21. Attributes: &filer_pb.FuseAttributes{
  22. Mtime: time.Now().Unix(),
  23. Crtime: time.Now().Unix(),
  24. FileMode: uint32(os.ModeDir) | in.Mode&^uint32(wfs.option.Umask),
  25. Uid: in.Uid,
  26. Gid: in.Gid,
  27. },
  28. }
  29. dirFullPath := wfs.inodeToPath.GetPath(in.NodeId)
  30. entryFullPath := dirFullPath.Child(name)
  31. err := wfs.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
  32. wfs.mapPbIdFromLocalToFiler(newEntry)
  33. defer wfs.mapPbIdFromFilerToLocal(newEntry)
  34. request := &filer_pb.CreateEntryRequest{
  35. Directory: string(dirFullPath),
  36. Entry: newEntry,
  37. Signatures: []int32{wfs.signature},
  38. }
  39. glog.V(1).Infof("mkdir: %v", request)
  40. if err := filer_pb.CreateEntry(client, request); err != nil {
  41. glog.V(0).Infof("mkdir %s: %v", entryFullPath, err)
  42. return err
  43. }
  44. if err := wfs.metaCache.InsertEntry(context.Background(), filer.FromPbEntry(request.Directory, request.Entry)); err != nil {
  45. return fmt.Errorf("local mkdir dir %s: %v", entryFullPath, err)
  46. }
  47. return nil
  48. })
  49. glog.V(0).Infof("mkdir %s: %v", entryFullPath, err)
  50. if err != nil {
  51. return fuse.EIO
  52. }
  53. inode := wfs.inodeToPath.GetInode(entryFullPath)
  54. wfs.outputPbEntry(out, inode, newEntry)
  55. return fuse.OK
  56. }
  57. func (wfs *WFS) Rmdir(cancel <-chan struct{}, header *fuse.InHeader, name string) (code fuse.Status) {
  58. if name == "." {
  59. return fuse.Status(syscall.EINVAL)
  60. }
  61. if name == ".." {
  62. return fuse.Status(syscall.ENOTEMPTY)
  63. }
  64. dirFullPath := wfs.inodeToPath.GetPath(header.NodeId)
  65. entryFullPath := dirFullPath.Child(name)
  66. glog.V(3).Infof("remove directory: %v", entryFullPath)
  67. ignoreRecursiveErr := true // ignore recursion error since the OS should manage it
  68. err := filer_pb.Remove(wfs, string(dirFullPath), name, true, true, ignoreRecursiveErr, false, []int32{wfs.signature})
  69. if err != nil {
  70. glog.V(0).Infof("remove %s: %v", entryFullPath, err)
  71. if strings.Contains(err.Error(), filer.MsgFailDelNonEmptyFolder) {
  72. return fuse.Status(syscall.ENOTEMPTY)
  73. }
  74. return fuse.ENOENT
  75. }
  76. wfs.metaCache.DeleteEntry(context.Background(), entryFullPath)
  77. return fuse.OK
  78. }