You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.9 KiB

  1. package filesys
  2. import (
  3. "context"
  4. "os"
  5. "syscall"
  6. "time"
  7. "github.com/chrislusf/seaweedfs/weed/filer"
  8. "github.com/chrislusf/seaweedfs/weed/glog"
  9. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  10. "github.com/seaweedfs/fuse"
  11. "github.com/seaweedfs/fuse/fs"
  12. )
  13. var _ = fs.NodeSymlinker(&Dir{})
  14. var _ = fs.NodeReadlinker(&File{})
  15. func (dir *Dir) Symlink(ctx context.Context, req *fuse.SymlinkRequest) (fs.Node, error) {
  16. glog.V(4).Infof("Symlink: %v/%v to %v", dir.FullPath(), req.NewName, req.Target)
  17. request := &filer_pb.CreateEntryRequest{
  18. Directory: dir.FullPath(),
  19. Entry: &filer_pb.Entry{
  20. Name: req.NewName,
  21. IsDirectory: false,
  22. Attributes: &filer_pb.FuseAttributes{
  23. Mtime: time.Now().Unix(),
  24. Crtime: time.Now().Unix(),
  25. FileMode: uint32((os.FileMode(0777) | os.ModeSymlink) &^ dir.wfs.option.Umask),
  26. Uid: req.Uid,
  27. Gid: req.Gid,
  28. SymlinkTarget: req.Target,
  29. },
  30. },
  31. Signatures: []int32{dir.wfs.signature},
  32. }
  33. err := dir.wfs.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
  34. if err := filer_pb.CreateEntry(client, request); err != nil {
  35. glog.V(0).Infof("symlink %s/%s: %v", dir.FullPath(), req.NewName, err)
  36. return fuse.EIO
  37. }
  38. dir.wfs.metaCache.InsertEntry(context.Background(), filer.FromPbEntry(request.Directory, request.Entry))
  39. return nil
  40. })
  41. symlink := dir.newFile(req.NewName, request.Entry)
  42. return symlink, err
  43. }
  44. func (file *File) Readlink(ctx context.Context, req *fuse.ReadlinkRequest) (string, error) {
  45. if err := file.maybeLoadEntry(ctx); err != nil {
  46. return "", err
  47. }
  48. if os.FileMode(file.entry.Attributes.FileMode)&os.ModeSymlink == 0 {
  49. return "", fuse.Errno(syscall.EINVAL)
  50. }
  51. glog.V(4).Infof("Readlink: %v/%v => %v", file.dir.FullPath(), file.Name, file.entry.Attributes.SymlinkTarget)
  52. return file.entry.Attributes.SymlinkTarget, nil
  53. }