wfs_save.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package mount
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/hanwen/go-fuse/v2/fuse"
  6. "github.com/seaweedfs/seaweedfs/weed/filer"
  7. "github.com/seaweedfs/seaweedfs/weed/glog"
  8. "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
  9. "github.com/seaweedfs/seaweedfs/weed/util"
  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. }