aboutsummaryrefslogtreecommitdiff
path: root/weed/filesys/dir_link.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2018-12-25 22:45:44 -0800
committerChris Lu <chris.lu@gmail.com>2018-12-25 22:45:44 -0800
commit253f190f48ca1f66d1aa16ed423f43f01f710178 (patch)
treea62278f3c42510a52d4ed349c65e2567aa59f741 /weed/filesys/dir_link.go
parenta508d560216f1f44b37aaefcc0d446a357adad57 (diff)
downloadseaweedfs-253f190f48ca1f66d1aa16ed423f43f01f710178.tar.xz
seaweedfs-253f190f48ca1f66d1aa16ed423f43f01f710178.zip
weed mount add symlink support
Diffstat (limited to 'weed/filesys/dir_link.go')
-rw-r--r--weed/filesys/dir_link.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/weed/filesys/dir_link.go b/weed/filesys/dir_link.go
new file mode 100644
index 000000000..5870cf3a4
--- /dev/null
+++ b/weed/filesys/dir_link.go
@@ -0,0 +1,66 @@
+package filesys
+
+import (
+ "context"
+ "os"
+ "syscall"
+ "time"
+
+ "bazil.org/fuse"
+ "bazil.org/fuse/fs"
+ "github.com/chrislusf/seaweedfs/weed/glog"
+ "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
+)
+
+var _ = fs.NodeSymlinker(&Dir{})
+var _ = fs.NodeReadlinker(&File{})
+
+func (dir *Dir) Symlink(ctx context.Context, req *fuse.SymlinkRequest) (fs.Node, error) {
+
+ glog.V(3).Infof("Symlink: %v/%v to %v", dir.Path, req.NewName, req.Target)
+
+ request := &filer_pb.CreateEntryRequest{
+ Directory: dir.Path,
+ Entry: &filer_pb.Entry{
+ Name: req.NewName,
+ IsDirectory: false,
+ Attributes: &filer_pb.FuseAttributes{
+ Mtime: time.Now().Unix(),
+ Crtime: time.Now().Unix(),
+ FileMode: uint32(os.FileMode(0755) | os.ModeSymlink),
+ Uid: req.Uid,
+ Gid: req.Gid,
+ SymlinkTarget: req.Target,
+ },
+ },
+ }
+
+ err := dir.wfs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
+ if _, err := client.CreateEntry(ctx, request); err != nil {
+ glog.V(0).Infof("symlink %s/%s: %v", dir.Path, req.NewName, err)
+ return fuse.EIO
+ }
+ return nil
+ })
+
+ symlink := dir.newFile(req.NewName, request.Entry)
+
+ return symlink, err
+
+}
+
+func (file *File) Readlink(ctx context.Context, req *fuse.ReadlinkRequest) (string, error) {
+
+ if err := file.maybeLoadAttributes(ctx); err != nil {
+ return "", err
+ }
+
+ if os.FileMode(file.entry.Attributes.FileMode)&os.ModeSymlink == 0 {
+ return "", fuse.Errno(syscall.EINVAL)
+ }
+
+ glog.V(3).Infof("Readlink: %v/%v => %v", file.dir.Path, file.Name, file.entry.Attributes.SymlinkTarget)
+
+ return file.entry.Attributes.SymlinkTarget, nil
+
+}