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.

67 lines
1.8 KiB

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/chrislusf/seaweedfs/weed/util"
  9. "github.com/hanwen/go-fuse/v2/fuse"
  10. "syscall"
  11. )
  12. func (wfs *WFS) saveEntry(path util.FullPath, entry *filer_pb.Entry) (code fuse.Status) {
  13. parentDir, _ := path.DirAndName()
  14. err := wfs.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
  15. wfs.mapPbIdFromLocalToFiler(entry)
  16. defer wfs.mapPbIdFromFilerToLocal(entry)
  17. request := &filer_pb.UpdateEntryRequest{
  18. Directory: parentDir,
  19. Entry: entry,
  20. Signatures: []int32{wfs.signature},
  21. }
  22. glog.V(1).Infof("save entry: %v", request)
  23. _, err := client.UpdateEntry(context.Background(), request)
  24. if err != nil {
  25. return fmt.Errorf("UpdateEntry dir %s: %v", path, err)
  26. }
  27. if err := wfs.metaCache.UpdateEntry(context.Background(), filer.FromPbEntry(request.Directory, request.Entry)); err != nil {
  28. return fmt.Errorf("UpdateEntry dir %s: %v", path, err)
  29. }
  30. return nil
  31. })
  32. if err != nil {
  33. glog.Errorf("saveEntry %s: %v", path, err)
  34. return fuse.EIO
  35. }
  36. return fuse.OK
  37. }
  38. func (wfs *WFS) mapPbIdFromFilerToLocal(entry *filer_pb.Entry) {
  39. if entry.Attributes == nil {
  40. return
  41. }
  42. entry.Attributes.Uid, entry.Attributes.Gid = wfs.option.UidGidMapper.FilerToLocal(entry.Attributes.Uid, entry.Attributes.Gid)
  43. }
  44. func (wfs *WFS) mapPbIdFromLocalToFiler(entry *filer_pb.Entry) {
  45. if entry.Attributes == nil {
  46. return
  47. }
  48. entry.Attributes.Uid, entry.Attributes.Gid = wfs.option.UidGidMapper.LocalToFiler(entry.Attributes.Uid, entry.Attributes.Gid)
  49. }
  50. func checkName(name string) fuse.Status {
  51. if len(name) >= 4096 {
  52. return fuse.Status(syscall.ENAMETOOLONG)
  53. }
  54. return fuse.OK
  55. }