mirror of
https://github.com/rclone/rclone.git
synced 2024-12-30 08:53:40 +08:00
mount: introduce symlink support #2975
This commit is contained in:
parent
06657c49a0
commit
db1ed69693
|
@ -7,6 +7,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -33,7 +34,7 @@ func (d *Dir) Attr(ctx context.Context, a *fuse.Attr) (err error) {
|
||||||
a.Valid = time.Duration(d.fsys.opt.AttrTimeout)
|
a.Valid = time.Duration(d.fsys.opt.AttrTimeout)
|
||||||
a.Gid = d.VFS().Opt.GID
|
a.Gid = d.VFS().Opt.GID
|
||||||
a.Uid = d.VFS().Opt.UID
|
a.Uid = d.VFS().Opt.UID
|
||||||
a.Mode = os.ModeDir | os.FileMode(d.VFS().Opt.DirPerms)
|
a.Mode = d.Mode()
|
||||||
modTime := d.ModTime()
|
modTime := d.ModTime()
|
||||||
a.Atime = modTime
|
a.Atime = modTime
|
||||||
a.Mtime = modTime
|
a.Mtime = modTime
|
||||||
|
@ -140,11 +141,13 @@ var _ fusefs.NodeCreater = (*Dir)(nil)
|
||||||
// Create makes a new file
|
// Create makes a new file
|
||||||
func (d *Dir) Create(ctx context.Context, req *fuse.CreateRequest, resp *fuse.CreateResponse) (node fusefs.Node, handle fusefs.Handle, err error) {
|
func (d *Dir) Create(ctx context.Context, req *fuse.CreateRequest, resp *fuse.CreateResponse) (node fusefs.Node, handle fusefs.Handle, err error) {
|
||||||
defer log.Trace(d, "name=%q", req.Name)("node=%v, handle=%v, err=%v", &node, &handle, &err)
|
defer log.Trace(d, "name=%q", req.Name)("node=%v, handle=%v, err=%v", &node, &handle, &err)
|
||||||
file, err := d.Dir.Create(req.Name, int(req.Flags))
|
// translate the fuse flags to os flags
|
||||||
|
osFlags := int(req.Flags) | os.O_CREATE
|
||||||
|
file, err := d.Dir.Create(req.Name, osFlags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, translateError(err)
|
return nil, nil, translateError(err)
|
||||||
}
|
}
|
||||||
fh, err := file.Open(int(req.Flags) | os.O_CREATE)
|
fh, err := file.Open(osFlags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, translateError(err)
|
return nil, nil, translateError(err)
|
||||||
}
|
}
|
||||||
|
@ -200,7 +203,6 @@ func (d *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDir fusefs
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("unknown Dir type %T", newDir)
|
return fmt.Errorf("unknown Dir type %T", newDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = d.Dir.Rename(req.OldName, req.NewName, destDir.Dir)
|
err = d.Dir.Rename(req.OldName, req.NewName, destDir.Dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return translateError(err)
|
return translateError(err)
|
||||||
|
@ -239,6 +241,24 @@ func (d *Dir) Link(ctx context.Context, req *fuse.LinkRequest, old fusefs.Node)
|
||||||
return nil, syscall.ENOSYS
|
return nil, syscall.ENOSYS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ fusefs.NodeSymlinker = (*Dir)(nil)
|
||||||
|
|
||||||
|
// Symlink create a symbolic link.
|
||||||
|
func (d *Dir) Symlink(ctx context.Context, req *fuse.SymlinkRequest) (node fusefs.Node, err error) {
|
||||||
|
defer log.Trace(d, "newname=%v, target=%v", req.NewName, req.Target)("node=%v, err=%v", &node, &err)
|
||||||
|
|
||||||
|
newName := path.Join(d.Path(), req.NewName)
|
||||||
|
target := req.Target
|
||||||
|
|
||||||
|
n, err := d.VFS().CreateSymlink(target, newName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
node = &File{n.(*vfs.File), d.fsys}
|
||||||
|
return node, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Check interface satisfied
|
// Check interface satisfied
|
||||||
var _ fusefs.NodeMknoder = (*Dir)(nil)
|
var _ fusefs.NodeMknoder = (*Dir)(nil)
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ func (f *File) Attr(ctx context.Context, a *fuse.Attr) (err error) {
|
||||||
Blocks := (Size + 511) / 512
|
Blocks := (Size + 511) / 512
|
||||||
a.Gid = f.VFS().Opt.GID
|
a.Gid = f.VFS().Opt.GID
|
||||||
a.Uid = f.VFS().Opt.UID
|
a.Uid = f.VFS().Opt.UID
|
||||||
a.Mode = os.FileMode(f.VFS().Opt.FilePerms)
|
a.Mode = f.File.Mode() &^ os.ModeAppend
|
||||||
a.Size = Size
|
a.Size = Size
|
||||||
a.Atime = modTime
|
a.Atime = modTime
|
||||||
a.Mtime = modTime
|
a.Mtime = modTime
|
||||||
|
@ -129,3 +129,11 @@ func (f *File) Removexattr(ctx context.Context, req *fuse.RemovexattrRequest) er
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ fusefs.NodeRemovexattrer = (*File)(nil)
|
var _ fusefs.NodeRemovexattrer = (*File)(nil)
|
||||||
|
|
||||||
|
var _ fusefs.NodeReadlinker = (*File)(nil)
|
||||||
|
|
||||||
|
// Readlink read symbolic link target.
|
||||||
|
func (f *File) Readlink(ctx context.Context, req *fuse.ReadlinkRequest) (ret string, err error) {
|
||||||
|
defer log.Trace(f, "")("ret=%v, err=%v", &ret, &err)
|
||||||
|
return f.VFS().Readlink(f.Path())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user