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.

59 lines
1.6 KiB

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