Node.Symlink()

This commit is contained in:
Ben Johnson
2020-10-13 12:51:39 -06:00
parent b3693846a0
commit 410d56f334

15
node.go
View File

@@ -40,6 +40,10 @@ type Node struct {
path string // path within file system path string // path within file system
} }
func NewNode(fs *FS, path string) *Node {
return &Node{fs: fs, path: path}
}
func (n *Node) srcpath() string { func (n *Node) srcpath() string {
return filepath.Join(n.fs.SourcePath, n.path) return filepath.Join(n.fs.SourcePath, n.path)
} }
@@ -85,7 +89,7 @@ func (n *Node) Lookup(ctx context.Context, name string) (fs.Node, error) {
if _, err := os.Stat(srcpath); os.IsNotExist(err) { if _, err := os.Stat(srcpath); os.IsNotExist(err) {
return nil, syscall.ENOENT return nil, syscall.ENOENT
} }
return &Node{fs: n.fs, path: path}, nil return NewNode(n.fs, path), nil
} }
func (n *Node) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) { func (n *Node) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
@@ -198,9 +202,12 @@ func (n *Node) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse
} }
// Symlink creates a new symbolic link in the receiver, which must be a directory. // Symlink creates a new symbolic link in the receiver, which must be a directory.
// func (n *Node) Symlink(ctx context.Context, req *fuse.SymlinkRequest) (fs.Node, error) {
// TODO is the above true about directories? if err := os.Symlink(req.Target, req.NewName); err != nil {
func (n *Node) Symlink(ctx context.Context, req *fuse.SymlinkRequest) (fs.Node, error) { panic("TODO") } return nil, err
}
return NewNode(n.fs, req.NewName), nil
}
// Readlink reads a symbolic link. // Readlink reads a symbolic link.
func (n *Node) Readlink(ctx context.Context, req *fuse.ReadlinkRequest) (string, error) { func (n *Node) Readlink(ctx context.Context, req *fuse.ReadlinkRequest) (string, error) {