2018-12-26 06:45:44 +00:00
|
|
|
package filesys
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
|
2020-04-22 22:40:47 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/filer2"
|
2018-12-26 06:45:44 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
2019-01-17 01:17:19 +00:00
|
|
|
"github.com/seaweedfs/fuse"
|
|
|
|
"github.com/seaweedfs/fuse/fs"
|
2018-12-26 06:45:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = fs.NodeSymlinker(&Dir{})
|
|
|
|
var _ = fs.NodeReadlinker(&File{})
|
|
|
|
|
|
|
|
func (dir *Dir) Symlink(ctx context.Context, req *fuse.SymlinkRequest) (fs.Node, error) {
|
|
|
|
|
2020-03-26 07:08:14 +00:00
|
|
|
glog.V(3).Infof("Symlink: %v/%v to %v", dir.FullPath(), req.NewName, req.Target)
|
2018-12-26 06:45:44 +00:00
|
|
|
|
|
|
|
request := &filer_pb.CreateEntryRequest{
|
2020-03-26 07:08:14 +00:00
|
|
|
Directory: dir.FullPath(),
|
2018-12-26 06:45:44 +00:00
|
|
|
Entry: &filer_pb.Entry{
|
|
|
|
Name: req.NewName,
|
|
|
|
IsDirectory: false,
|
|
|
|
Attributes: &filer_pb.FuseAttributes{
|
|
|
|
Mtime: time.Now().Unix(),
|
|
|
|
Crtime: time.Now().Unix(),
|
2019-07-24 07:03:05 +00:00
|
|
|
FileMode: uint32((os.FileMode(0777) | os.ModeSymlink) &^ dir.wfs.option.Umask),
|
2018-12-26 06:45:44 +00:00
|
|
|
Uid: req.Uid,
|
|
|
|
Gid: req.Gid,
|
|
|
|
SymlinkTarget: req.Target,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-02-26 05:50:12 +00:00
|
|
|
err := dir.wfs.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
|
|
|
if err := filer_pb.CreateEntry(client, request); err != nil {
|
2020-03-26 07:08:14 +00:00
|
|
|
glog.V(0).Infof("symlink %s/%s: %v", dir.FullPath(), req.NewName, err)
|
2018-12-26 06:45:44 +00:00
|
|
|
return fuse.EIO
|
|
|
|
}
|
2020-04-22 22:40:47 +00:00
|
|
|
|
2020-06-28 17:18:32 +00:00
|
|
|
dir.wfs.metaCache.InsertEntry(context.Background(), filer2.FromPbEntry(request.Directory, request.Entry))
|
2020-04-22 22:40:47 +00:00
|
|
|
|
2018-12-26 06:45:44 +00:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
symlink := dir.newFile(req.NewName, request.Entry)
|
|
|
|
|
|
|
|
return symlink, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (file *File) Readlink(ctx context.Context, req *fuse.ReadlinkRequest) (string, error) {
|
|
|
|
|
2019-12-16 05:07:01 +00:00
|
|
|
if err := file.maybeLoadEntry(ctx); err != nil {
|
2018-12-26 06:45:44 +00:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
if os.FileMode(file.entry.Attributes.FileMode)&os.ModeSymlink == 0 {
|
|
|
|
return "", fuse.Errno(syscall.EINVAL)
|
|
|
|
}
|
|
|
|
|
2020-03-26 07:08:14 +00:00
|
|
|
glog.V(3).Infof("Readlink: %v/%v => %v", file.dir.FullPath(), file.Name, file.entry.Attributes.SymlinkTarget)
|
2018-12-26 06:45:44 +00:00
|
|
|
|
|
|
|
return file.entry.Attributes.SymlinkTarget, nil
|
|
|
|
|
|
|
|
}
|