mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-24 05:59:55 +08:00
Merge pull request #5525 from overbool/fix/issue-#5055
fix(unixfs): issue #5055
This commit is contained in:
@ -138,7 +138,7 @@ The JSON output contains type information.
|
||||
switch link.Cid.Type() {
|
||||
case cid.Raw:
|
||||
// No need to check with raw leaves
|
||||
t = unixfspb.Data_File
|
||||
t = unixfs.TFile
|
||||
case cid.DagProtobuf:
|
||||
linkNode, err := link.GetNode(req.Context(), dserv)
|
||||
if err == ipld.ErrNotFound && !resolve {
|
||||
@ -193,7 +193,7 @@ The JSON output contains type information.
|
||||
fmt.Fprintln(w, "Hash\tSize\tName")
|
||||
}
|
||||
for _, link := range object.Links {
|
||||
if link.Type == unixfspb.Data_Directory {
|
||||
if link.Type == unixfs.TDirectory {
|
||||
link.Name += "/"
|
||||
}
|
||||
fmt.Fprintf(w, "%s\t%v\t%s\n", link.Hash, link.Size, link.Name)
|
||||
|
@ -14,7 +14,6 @@ import (
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
unixfs "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs"
|
||||
uio "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/io"
|
||||
unixfspb "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/pb"
|
||||
merkledag "gx/ipfs/QmcBoNcAP6qDjgRBew7yjvCqHq7p5jMstE44jPUBWBxzsV/go-merkledag"
|
||||
path "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path"
|
||||
resolver "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path/resolver"
|
||||
@ -135,13 +134,13 @@ possible, please use 'ipfs ls' instead.
|
||||
}
|
||||
|
||||
switch t {
|
||||
case unixfspb.Data_File:
|
||||
case unixfs.TFile:
|
||||
break
|
||||
case unixfspb.Data_HAMTShard:
|
||||
case unixfs.THAMTShard:
|
||||
// We need a streaming ls API for this.
|
||||
res.SetError(fmt.Errorf("cannot list large directories yet"), cmdkit.ErrNormal)
|
||||
return
|
||||
case unixfspb.Data_Directory:
|
||||
case unixfs.TDirectory:
|
||||
links := make([]LsLink, len(merkleNode.Links()))
|
||||
output.Objects[hash].Links = links
|
||||
for i, link := range merkleNode.Links() {
|
||||
@ -167,14 +166,14 @@ possible, please use 'ipfs ls' instead.
|
||||
Hash: link.Cid.String(),
|
||||
Type: t.String(),
|
||||
}
|
||||
if t == unixfspb.Data_File {
|
||||
if t == unixfs.TFile {
|
||||
lsLink.Size = d.FileSize()
|
||||
} else {
|
||||
lsLink.Size = link.Size
|
||||
}
|
||||
links[i] = lsLink
|
||||
}
|
||||
case unixfspb.Data_Symlink:
|
||||
case unixfs.TSymlink:
|
||||
res.SetError(fmt.Errorf("cannot list symlinks yet"), cmdkit.ErrNormal)
|
||||
return
|
||||
default:
|
||||
|
@ -11,8 +11,8 @@ import (
|
||||
"syscall"
|
||||
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
ft "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs"
|
||||
uio "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/io"
|
||||
ftpb "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/pb"
|
||||
mdag "gx/ipfs/QmcBoNcAP6qDjgRBew7yjvCqHq7p5jMstE44jPUBWBxzsV/go-merkledag"
|
||||
path "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path"
|
||||
|
||||
@ -21,7 +21,6 @@ import (
|
||||
fs "gx/ipfs/QmSJBsmLP1XMjv8hxYg2rUMdPDB7YUpyBo9idjrJ6Cmq6F/fuse/fs"
|
||||
logging "gx/ipfs/QmZChCsSt8DctjceaL56Eibc29CVQq4dGKRXC5JRZ6Ppae/go-log"
|
||||
ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
|
||||
proto "gx/ipfs/QmdxUuburamoF6zF9qjeQC4WYcWGbWuRmdLacMEsW8ioD8/gogo-protobuf/proto"
|
||||
)
|
||||
|
||||
var log = logging.Logger("fuse/ipfs")
|
||||
@ -93,13 +92,16 @@ func (*Root) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
|
||||
type Node struct {
|
||||
Ipfs *core.IpfsNode
|
||||
Nd ipld.Node
|
||||
cached *ftpb.Data
|
||||
cached *ft.FSNode
|
||||
}
|
||||
|
||||
func (s *Node) loadData() error {
|
||||
if pbnd, ok := s.Nd.(*mdag.ProtoNode); ok {
|
||||
s.cached = new(ftpb.Data)
|
||||
return proto.Unmarshal(pbnd.Data(), s.cached)
|
||||
fsn, err := ft.FSNodeFromBytes(pbnd.Data())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.cached = fsn
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -119,23 +121,23 @@ func (s *Node) Attr(ctx context.Context, a *fuse.Attr) error {
|
||||
return fmt.Errorf("readonly: loadData() failed: %s", err)
|
||||
}
|
||||
}
|
||||
switch s.cached.GetType() {
|
||||
case ftpb.Data_Directory, ftpb.Data_HAMTShard:
|
||||
switch s.cached.Type() {
|
||||
case ft.TDirectory, ft.THAMTShard:
|
||||
a.Mode = os.ModeDir | 0555
|
||||
case ftpb.Data_File:
|
||||
size := s.cached.GetFilesize()
|
||||
case ft.TFile:
|
||||
size := s.cached.FileSize()
|
||||
a.Mode = 0444
|
||||
a.Size = uint64(size)
|
||||
a.Blocks = uint64(len(s.Nd.Links()))
|
||||
case ftpb.Data_Raw:
|
||||
case ft.TRaw:
|
||||
a.Mode = 0444
|
||||
a.Size = uint64(len(s.cached.GetData()))
|
||||
a.Size = uint64(len(s.cached.Data()))
|
||||
a.Blocks = uint64(len(s.Nd.Links()))
|
||||
case ftpb.Data_Symlink:
|
||||
case ft.TSymlink:
|
||||
a.Mode = 0777 | os.ModeSymlink
|
||||
a.Size = uint64(len(s.cached.GetData()))
|
||||
a.Size = uint64(len(s.cached.Data()))
|
||||
default:
|
||||
return fmt.Errorf("invalid data type - %s", s.cached.GetType())
|
||||
return fmt.Errorf("invalid data type - %s", s.cached.Type())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -192,21 +194,20 @@ func (s *Node) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
|
||||
case *mdag.RawNode:
|
||||
t = fuse.DT_File
|
||||
case *mdag.ProtoNode:
|
||||
var data ftpb.Data
|
||||
if err := proto.Unmarshal(nd.Data(), &data); err != nil {
|
||||
if fsn, err := ft.FSNodeFromBytes(nd.Data()); err != nil {
|
||||
log.Warning("failed to unmarshal protonode data field:", err)
|
||||
} else {
|
||||
switch data.GetType() {
|
||||
case ftpb.Data_Directory, ftpb.Data_HAMTShard:
|
||||
switch fsn.Type() {
|
||||
case ft.TDirectory, ft.THAMTShard:
|
||||
t = fuse.DT_Dir
|
||||
case ftpb.Data_File, ftpb.Data_Raw:
|
||||
case ft.TFile, ft.TRaw:
|
||||
t = fuse.DT_File
|
||||
case ftpb.Data_Symlink:
|
||||
case ft.TSymlink:
|
||||
t = fuse.DT_Link
|
||||
case ftpb.Data_Metadata:
|
||||
case ft.TMetadata:
|
||||
log.Error("metadata object in fuse should contain its wrapped type")
|
||||
default:
|
||||
log.Error("unrecognized protonode data type: ", data.GetType())
|
||||
log.Error("unrecognized protonode data type: ", fsn.Type())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -230,10 +231,10 @@ func (s *Node) Getxattr(ctx context.Context, req *fuse.GetxattrRequest, resp *fu
|
||||
}
|
||||
|
||||
func (s *Node) Readlink(ctx context.Context, req *fuse.ReadlinkRequest) (string, error) {
|
||||
if s.cached == nil || s.cached.GetType() != ftpb.Data_Symlink {
|
||||
if s.cached == nil || s.cached.Type() != ft.TSymlink {
|
||||
return "", fuse.Errno(syscall.EINVAL)
|
||||
}
|
||||
return string(s.cached.GetData()), nil
|
||||
return string(s.cached.Data()), nil
|
||||
}
|
||||
|
||||
func (s *Node) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error {
|
||||
|
Reference in New Issue
Block a user