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

Commit

Permalink
Fix in size func
Browse files Browse the repository at this point in the history
  • Loading branch information
Cory Schwartz committed Apr 16, 2021
1 parent 77ff92d commit 7e96bad
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
20 changes: 1 addition & 19 deletions io/dagreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,9 @@ func NewDagReader(ctx context.Context, n ipld.Node, serv ipld.NodeGetter) (DagRe
}

switch fsNode.Type() {
case unixfs.TFile:
case unixfs.TFile, unixfs.TRaw:
size = fsNode.FileSize()

case unixfs.TRaw:
stat, err := n.Stat()
if err != nil {
return nil, err
}
size = uint64(stat.DataSize)
for _, link := range n.Links() {
ln, err := link.GetNode(ctx, serv)
if err != nil {
return nil, err
}
stat, err := ln.Stat()
if err != nil {
return nil, err
}
size += uint64(stat.DataSize)
}

case unixfs.TDirectory, unixfs.THAMTShard:
// Dont allow reading directories
return nil, ErrIsDir
Expand Down
4 changes: 2 additions & 2 deletions unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ func size(pbdata *pb.Data) (uint64, error) {
switch pbdata.GetType() {
case pb.Data_Directory, pb.Data_HAMTShard:
return 0, errors.New("can't get data size of directory")
case pb.Data_File:
case pb.Data_File, pb.Data_Raw:
return pbdata.GetFilesize(), nil
case pb.Data_Symlink, pb.Data_Raw:
case pb.Data_Symlink:
return uint64(len(pbdata.GetData())), nil
default:
return 0, errors.New("unrecognized node data type")
Expand Down

0 comments on commit 7e96bad

Please sign in to comment.