Skip to content

Commit

Permalink
refactor: make if more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Dec 12, 2022
1 parent 68f8b42 commit 845ebef
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions core/coreapi/unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,39 +271,37 @@ func (api *UnixfsAPI) processLink(ctx context.Context, linkres ft.LinkResult, se
lnk.Type = coreiface.TFile
lnk.Size = linkres.Link.Size
case cid.DagProtobuf:
if settings.UseCumulativeSize {
lnk.Size = linkres.Link.Size
}

if !settings.ResolveChildren {
break
}

linkNode, err := linkres.Link.GetNode(ctx, api.dag)
if err != nil {
lnk.Err = err
break
}

if pn, ok := linkNode.(*merkledag.ProtoNode); ok {
d, err := ft.FSNodeFromBytes(pn.Data())
if settings.ResolveChildren {
linkNode, err := linkres.Link.GetNode(ctx, api.dag)
if err != nil {
lnk.Err = err
break
}
switch d.Type() {
case ft.TFile, ft.TRaw:
lnk.Type = coreiface.TFile
case ft.THAMTShard, ft.TDirectory, ft.TMetadata:
lnk.Type = coreiface.TDirectory
case ft.TSymlink:
lnk.Type = coreiface.TSymlink
lnk.Target = string(d.Data())
}
if !settings.UseCumulativeSize {
lnk.Size = d.FileSize()

if pn, ok := linkNode.(*merkledag.ProtoNode); ok {
d, err := ft.FSNodeFromBytes(pn.Data())
if err != nil {
lnk.Err = err
break
}
switch d.Type() {
case ft.TFile, ft.TRaw:
lnk.Type = coreiface.TFile
case ft.THAMTShard, ft.TDirectory, ft.TMetadata:
lnk.Type = coreiface.TDirectory
case ft.TSymlink:
lnk.Type = coreiface.TSymlink
lnk.Target = string(d.Data())
}
if !settings.UseCumulativeSize {
lnk.Size = d.FileSize()
}
}
}

if settings.UseCumulativeSize {
lnk.Size = linkres.Link.Size
}
}

return lnk
Expand Down

0 comments on commit 845ebef

Please sign in to comment.