Skip to content

Commit

Permalink
mount2: introduce symlink support rclone#2975
Browse files Browse the repository at this point in the history
  • Loading branch information
pasnox authored and ncw committed Dec 13, 2024
1 parent db1ed69 commit d629102
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cmd/mount2/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@ func (f *FS) SetDebug(debug bool) {

// get the Mode from a vfs Node
func getMode(node os.FileInfo) uint32 {
Mode := node.Mode().Perm()
if node.IsDir() {
vfsMode := node.Mode()
Mode := vfsMode.Perm()
if vfsMode&os.ModeDir != 0 {
Mode |= fuse.S_IFDIR
} else if vfsMode&os.ModeSymlink != 0 {
Mode |= fuse.S_IFLNK
} else if vfsMode&os.ModeNamedPipe != 0 {
Mode |= fuse.S_IFIFO
} else {
Mode |= fuse.S_IFREG
}
Expand Down
28 changes: 28 additions & 0 deletions cmd/mount2/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,31 @@ func (n *Node) Listxattr(ctx context.Context, dest []byte) (uint32, syscall.Errn
}

var _ fusefs.NodeListxattrer = (*Node)(nil)

var _ fusefs.NodeReadlinker = (*Node)(nil)

// Readlink read symbolic link target.
func (n *Node) Readlink(ctx context.Context) (ret []byte, err syscall.Errno) {
defer log.Trace(n, "")("ret=%v, err=%v", &ret, &err)
path := n.node.Path()
s, serr := n.node.VFS().Readlink(path)
return []byte(s), translateError(serr)
}

var _ fusefs.NodeSymlinker = (*Node)(nil)

// Symlink create symbolic link.
func (n *Node) Symlink(ctx context.Context, target, name string, out *fuse.EntryOut) (node *fusefs.Inode, err syscall.Errno) {
defer log.Trace(n, "name=%v, target=%v", name, target)("node=%v, err=%v", &node, &err)
fullPath := path.Join(n.node.Path(), name)
vfsNode, serr := n.node.VFS().CreateSymlink(target, fullPath)
if serr != nil {
return nil, translateError(serr)
}

n.fsys.setEntryOut(vfsNode, out)
newNode := newNode(n.fsys, vfsNode)
newInode := n.NewInode(ctx, newNode, fusefs.StableAttr{Mode: out.Attr.Mode})

return newInode, 0
}

0 comments on commit d629102

Please sign in to comment.