Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

fix(unixfs): issue #6 #7

Merged
merged 1 commit into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ func (d *Directory) childNode(name string) (FSNode, error) {
func (d *Directory) cacheNode(name string, nd ipld.Node) (FSNode, error) {
switch nd := nd.(type) {
case *dag.ProtoNode:
i, err := ft.FromBytes(nd.Data())
fsn, err := ft.FSNodeFromBytes(nd.Data())
if err != nil {
return nil, err
}

switch i.GetType() {
switch fsn.Type() {
case ufspb.Data_Directory, ufspb.Data_HAMTShard:
ndir, err := NewDirectory(d.ctx, name, nd, d, d.dserv)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ func (fi *File) Size() (int64, error) {
defer fi.nodelk.Unlock()
switch nd := fi.node.(type) {
case *dag.ProtoNode:
pbd, err := ft.FromBytes(nd.Data())
fsn, err := ft.FSNodeFromBytes(nd.Data())
if err != nil {
return 0, err
}
return int64(pbd.GetFilesize()), nil
return int64(fsn.FileSize()), nil
case *dag.RawNode:
return int64(len(nd.RawData())), nil
default:
Expand Down
8 changes: 4 additions & 4 deletions system.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ func NewRoot(parent context.Context, ds ipld.DAGService, node *dag.ProtoNode, pf
repub: repub,
}

pbn, err := ft.FromBytes(node.Data())
fsn, err := ft.FSNodeFromBytes(node.Data())
if err != nil {
log.Error("IPNS pointer was not unixfs node")
return nil, err
}

switch pbn.GetType() {
switch fsn.Type() {
case ft.TDirectory, ft.THAMTShard:
newDir, err := NewDirectory(parent, node.String(), node, root, ds)
if err != nil {
Expand All @@ -89,9 +89,9 @@ func NewRoot(parent context.Context, ds ipld.DAGService, node *dag.ProtoNode, pf

root.dir = newDir
case ft.TFile, ft.TMetadata, ft.TRaw:
return nil, fmt.Errorf("root can't be a file (unixfs type: %s)", pbn.GetType())
return nil, fmt.Errorf("root can't be a file (unixfs type: %s)", fsn.Type())
default:
return nil, fmt.Errorf("unrecognized unixfs type: %s", pbn.GetType())
return nil, fmt.Errorf("unrecognized unixfs type: %s", fsn.Type())
}
return root, nil
}
Expand Down