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.

121 lines
3.0 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
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. /** Create a directory
  15. *
  16. * Note that the mode argument may not have the type specification
  17. * bits set, i.e. S_ISDIR(mode) can be false. To obtain the
  18. * correct directory type bits use mode|S_IFDIR
  19. * */
  20. func (wfs *WFS) Mkdir(cancel <-chan struct{}, in *fuse.MkdirIn, name string, out *fuse.EntryOut) (code fuse.Status) {
  21. if wfs.IsOverQuota {
  22. return fuse.Status(syscall.ENOSPC)
  23. }
  24. if s := checkName(name); s != fuse.OK {
  25. return s
  26. }
  27. newEntry := &filer_pb.Entry{
  28. Name: name,
  29. IsDirectory: true,
  30. Attributes: &filer_pb.FuseAttributes{
  31. Mtime: time.Now().Unix(),
  32. Crtime: time.Now().Unix(),
  33. FileMode: uint32(os.ModeDir) | in.Mode&^uint32(wfs.option.Umask),
  34. Uid: in.Uid,
  35. Gid: in.Gid,
  36. },
  37. }
  38. dirFullPath, code := wfs.inodeToPath.GetPath(in.NodeId)
  39. if code != fuse.OK {
  40. return
  41. }
  42. entryFullPath := dirFullPath.Child(name)
  43. err := wfs.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
  44. wfs.mapPbIdFromLocalToFiler(newEntry)
  45. defer wfs.mapPbIdFromFilerToLocal(newEntry)
  46. request := &filer_pb.CreateEntryRequest{
  47. Directory: string(dirFullPath),
  48. Entry: newEntry,
  49. Signatures: []int32{wfs.signature},
  50. }
  51. glog.V(1).Infof("mkdir: %v", request)
  52. if err := filer_pb.CreateEntry(client, request); err != nil {
  53. glog.V(0).Infof("mkdir %s: %v", entryFullPath, err)
  54. return err
  55. }
  56. if err := wfs.metaCache.InsertEntry(context.Background(), filer.FromPbEntry(request.Directory, request.Entry)); err != nil {
  57. return fmt.Errorf("local mkdir dir %s: %v", entryFullPath, err)
  58. }
  59. return nil
  60. })
  61. glog.V(3).Infof("mkdir %s: %v", entryFullPath, err)
  62. if err != nil {
  63. return fuse.EIO
  64. }
  65. inode := wfs.inodeToPath.Lookup(entryFullPath, newEntry.Attributes.Crtime, true, false, 0, true)
  66. wfs.outputPbEntry(out, inode, newEntry)
  67. return fuse.OK
  68. }
  69. /** Remove a directory */
  70. func (wfs *WFS) Rmdir(cancel <-chan struct{}, header *fuse.InHeader, name string) (code fuse.Status) {
  71. if name == "." {
  72. return fuse.Status(syscall.EINVAL)
  73. }
  74. if name == ".." {
  75. return fuse.Status(syscall.ENOTEMPTY)
  76. }
  77. dirFullPath, code := wfs.inodeToPath.GetPath(header.NodeId)
  78. if code != fuse.OK {
  79. return
  80. }
  81. entryFullPath := dirFullPath.Child(name)
  82. glog.V(3).Infof("remove directory: %v", entryFullPath)
  83. ignoreRecursiveErr := true // ignore recursion error since the OS should manage it
  84. err := filer_pb.Remove(wfs, string(dirFullPath), name, true, true, ignoreRecursiveErr, false, []int32{wfs.signature})
  85. if err != nil {
  86. glog.V(0).Infof("remove %s: %v", entryFullPath, err)
  87. if strings.Contains(err.Error(), filer.MsgFailDelNonEmptyFolder) {
  88. return fuse.Status(syscall.ENOTEMPTY)
  89. }
  90. return fuse.ENOENT
  91. }
  92. wfs.metaCache.DeleteEntry(context.Background(), entryFullPath)
  93. wfs.inodeToPath.RemovePath(entryFullPath)
  94. return fuse.OK
  95. }