Unverified Commit 323371cb authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #61 from ipfs/misc/archive-refactor

unixfile: precalc dir size
parents 0eb1ef8f cdf04ae3
1.3.0: QmUHJ8HKx96wtoMLAcHq2DB6H9V4aEUzbLtf8uGnfmtJoD
1.3.1: QmQ1JnYpnzkaurjW1yxkQxC2w3K1PorNE1nv1vaP5Le7sq
......@@ -20,6 +20,7 @@ type ufsDirectory struct {
ctx context.Context
dserv ipld.DAGService
dir uio.Directory
size int64
}
type ufsIterator struct {
......@@ -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 {
......@@ -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
}
......@@ -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
......
......@@ -79,6 +79,6 @@
"license": "",
"name": "go-unixfs",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "1.3.0"
"version": "1.3.1"
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment