aboutsummaryrefslogtreecommitdiff
path: root/weed/mount/wfs_save.go
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2022-02-12 23:08:56 -0800
committerchrislu <chris.lu@gmail.com>2022-02-12 23:08:56 -0800
commitc81833a1924ca2d9f78573d2d97f0d32a230782a (patch)
tree3420ff96b88036497f6fb097e432f2377d19f3ab /weed/mount/wfs_save.go
parent5c48c23235e33e1b800c68fce1e07e34c89ac8c6 (diff)
downloadseaweedfs-c81833a1924ca2d9f78573d2d97f0d32a230782a.tar.xz
seaweedfs-c81833a1924ca2d9f78573d2d97f0d32a230782a.zip
add directory setAttr
Diffstat (limited to 'weed/mount/wfs_save.go')
-rw-r--r--weed/mount/wfs_save.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/weed/mount/wfs_save.go b/weed/mount/wfs_save.go
new file mode 100644
index 000000000..240c010d8
--- /dev/null
+++ b/weed/mount/wfs_save.go
@@ -0,0 +1,59 @@
+package mount
+
+import (
+ "context"
+ "fmt"
+ "github.com/chrislusf/seaweedfs/weed/filer"
+ "github.com/chrislusf/seaweedfs/weed/glog"
+ "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
+ "github.com/chrislusf/seaweedfs/weed/util"
+ "github.com/hanwen/go-fuse/v2/fuse"
+)
+
+func (wfs *WFS) saveEntry(path util.FullPath, entry *filer_pb.Entry) (code fuse.Status) {
+
+ parentDir, _ := path.DirAndName()
+
+ err := wfs.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
+
+ wfs.mapPbIdFromLocalToFiler(entry)
+ defer wfs.mapPbIdFromFilerToLocal(entry)
+
+ request := &filer_pb.UpdateEntryRequest{
+ Directory: parentDir,
+ Entry: entry,
+ Signatures: []int32{wfs.signature},
+ }
+
+ glog.V(1).Infof("save entry: %v", request)
+ _, err := client.UpdateEntry(context.Background(), request)
+ if err != nil {
+ return fmt.Errorf("UpdateEntry dir %s: %v", path, err)
+ }
+
+ if err := wfs.metaCache.UpdateEntry(context.Background(), filer.FromPbEntry(request.Directory, request.Entry)); err != nil {
+ return fmt.Errorf("UpdateEntry dir %s: %v", path, err)
+ }
+
+ return nil
+ })
+ if err != nil {
+ glog.Errorf("saveEntry %s: %v", path, err)
+ return fuse.EIO
+ }
+
+ return fuse.OK
+}
+
+func (wfs *WFS) mapPbIdFromFilerToLocal(entry *filer_pb.Entry) {
+ if entry.Attributes == nil {
+ return
+ }
+ entry.Attributes.Uid, entry.Attributes.Gid = wfs.option.UidGidMapper.FilerToLocal(entry.Attributes.Uid, entry.Attributes.Gid)
+}
+func (wfs *WFS) mapPbIdFromLocalToFiler(entry *filer_pb.Entry) {
+ if entry.Attributes == nil {
+ return
+ }
+ entry.Attributes.Uid, entry.Attributes.Gid = wfs.option.UidGidMapper.LocalToFiler(entry.Attributes.Uid, entry.Attributes.Gid)
+}