1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-10 09:52:20 +08:00

implement symlinks in unixfs, first draft

License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
Jeromy
2015-08-12 12:17:52 -07:00
parent 8c652907de
commit d993bc04d6
10 changed files with 152 additions and 9 deletions

View File

@ -7,6 +7,8 @@ import (
"fmt"
"io"
"os"
"syscall"
"time"
fuse "github.com/ipfs/go-ipfs/Godeps/_workspace/src/bazil.org/fuse"
fs "github.com/ipfs/go-ipfs/Godeps/_workspace/src/bazil.org/fuse/fs"
@ -58,6 +60,8 @@ func (s *Root) Lookup(ctx context.Context, name string) (fs.Node, error) {
return nil, fuse.ENOENT
}
log.Error("RESOLVE: ", name)
ctx, _ = context.WithTimeout(ctx, time.Second/2)
nd, err := s.Ipfs.Resolver.ResolvePath(ctx, path.Path(name))
if err != nil {
// todo: make this error more versatile.
@ -118,6 +122,13 @@ func (s *Node) Attr(ctx context.Context, a *fuse.Attr) error {
Uid: uint32(os.Getuid()),
Gid: uint32(os.Getgid()),
}
case ftpb.Data_Symlink:
*a = fuse.Attr{
Mode: 0777 | os.ModeSymlink,
Size: uint64(len(s.cached.GetData())),
Uid: uint32(os.Getuid()),
Gid: uint32(os.Getgid()),
}
default:
return fmt.Errorf("Invalid data type - %s", s.cached.GetType())
@ -155,6 +166,13 @@ func (s *Node) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
return nil, fuse.ENOENT
}
func (s *Node) Readlink(ctx context.Context, req *fuse.ReadlinkRequest) (string, error) {
if s.cached.GetType() != ftpb.Data_Symlink {
return "", fuse.Errno(syscall.EINVAL)
}
return string(s.cached.GetData()), nil
}
func (s *Node) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error {
k, err := s.Nd.Key()
@ -204,6 +222,7 @@ type roNode interface {
fs.HandleReader
fs.Node
fs.NodeStringLookuper
fs.NodeReadlinker
}
var _ roNode = (*Node)(nil)