From d280dc3ee10d41aa50ea3cbfc73e7dee0906a544 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 8 Dec 2022 16:10:34 +0100 Subject: [PATCH] refactor: make if more clear --- core/coreapi/unixfs.go | 52 ++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/core/coreapi/unixfs.go b/core/coreapi/unixfs.go index b41c7d0f233..753a3d3a0ef 100644 --- a/core/coreapi/unixfs.go +++ b/core/coreapi/unixfs.go @@ -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