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.

72 lines
1.7 KiB

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. "time"
  11. )
  12. func (wfs *WFS) Mkdir(cancel <-chan struct{}, in *fuse.MkdirIn, name string, out *fuse.EntryOut) (code fuse.Status) {
  13. if s := checkName(name); s != fuse.OK {
  14. return s
  15. }
  16. newEntry := &filer_pb.Entry{
  17. Name: name,
  18. IsDirectory: true,
  19. Attributes: &filer_pb.FuseAttributes{
  20. Mtime: time.Now().Unix(),
  21. Crtime: time.Now().Unix(),
  22. FileMode: uint32(os.ModeDir) | in.Mode&^uint32(wfs.option.Umask),
  23. Uid: in.Uid,
  24. Gid: in.Gid,
  25. },
  26. }
  27. dirFullPath := wfs.inodeToPath.GetPath(in.NodeId)
  28. entryFullPath := dirFullPath.Child(name)
  29. err := wfs.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
  30. wfs.mapPbIdFromLocalToFiler(newEntry)
  31. defer wfs.mapPbIdFromFilerToLocal(newEntry)
  32. request := &filer_pb.CreateEntryRequest{
  33. Directory: string(dirFullPath),
  34. Entry: newEntry,
  35. Signatures: []int32{wfs.signature},
  36. }
  37. glog.V(1).Infof("mkdir: %v", request)
  38. if err := filer_pb.CreateEntry(client, request); err != nil {
  39. glog.V(0).Infof("mkdir %s: %v", entryFullPath, err)
  40. return err
  41. }
  42. if err := wfs.metaCache.InsertEntry(context.Background(), filer.FromPbEntry(request.Directory, request.Entry)); err != nil {
  43. return fmt.Errorf("local mkdir dir %s: %v", entryFullPath, err)
  44. }
  45. return nil
  46. })
  47. glog.V(0).Infof("mkdir %s: %v", entryFullPath, err)
  48. if err != nil {
  49. return fuse.EIO
  50. }
  51. inode := wfs.inodeToPath.GetInode(entryFullPath)
  52. wfs.outputPbEntry(out, inode, newEntry)
  53. return fuse.OK
  54. }