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

Commit

Permalink
Merge pull request #61 from ipfs/misc/archive-refactor
Browse files Browse the repository at this point in the history
unixfile: precalc dir size
  • Loading branch information
Stebalien authored Jan 30, 2019
2 parents 0eb1ef8 + cdf04ae commit 323371c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gx/lastpubver
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.0: QmUHJ8HKx96wtoMLAcHq2DB6H9V4aEUzbLtf8uGnfmtJoD
1.3.1: QmQ1JnYpnzkaurjW1yxkQxC2w3K1PorNE1nv1vaP5Le7sq
20 changes: 11 additions & 9 deletions file/unixfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type ufsDirectory struct {
ctx context.Context
dserv ipld.DAGService
dir uio.Directory
size int64
}

type ufsIterator struct {
Expand Down Expand Up @@ -118,12 +119,7 @@ func (d *ufsDirectory) Entries() files.DirIterator {
}

func (d *ufsDirectory) Size() (int64, error) {
n, err := d.dir.GetNode()
if err != nil {
return 0, err
}
s, err := n.Size()
return int64(s), err
return d.size, nil
}

type ufsFile struct {
Expand All @@ -134,17 +130,23 @@ func (f *ufsFile) Size() (int64, error) {
return int64(f.DagReader.Size()), nil
}

func newUnixfsDir(ctx context.Context, dserv ipld.DAGService, nd ipld.Node) (files.Directory, error) {
func newUnixfsDir(ctx context.Context, dserv ipld.DAGService, nd *dag.ProtoNode) (files.Directory, error) {
dir, err := uio.NewDirectoryFromNode(dserv, nd)
if err != nil {
return nil, err
}

size, err := nd.Size()
if err != nil {
return nil, err
}

return &ufsDirectory{
ctx: ctx,
dserv: dserv,

dir: dir,
dir: dir,
size: int64(size),
}, nil
}

Expand All @@ -156,7 +158,7 @@ func NewUnixfsFile(ctx context.Context, dserv ipld.DAGService, nd ipld.Node) (fi
return nil, err
}
if fsn.IsDir() {
return newUnixfsDir(ctx, dserv, nd)
return newUnixfsDir(ctx, dserv, dn)
}
if fsn.Type() == ft.TSymlink {
return files.NewLinkFile(string(fsn.Data()), nil), nil
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@
"license": "",
"name": "go-unixfs",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "1.3.0"
"version": "1.3.1"
}

0 comments on commit 323371c

Please sign in to comment.