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 { ...@@ -20,6 +20,7 @@ type ufsDirectory struct {
ctx context.Context ctx context.Context
dserv ipld.DAGService dserv ipld.DAGService
dir uio.Directory dir uio.Directory
size int64
} }
type ufsIterator struct { type ufsIterator struct {
...@@ -118,12 +119,7 @@ func (d *ufsDirectory) Entries() files.DirIterator { ...@@ -118,12 +119,7 @@ func (d *ufsDirectory) Entries() files.DirIterator {
} }
func (d *ufsDirectory) Size() (int64, error) { func (d *ufsDirectory) Size() (int64, error) {
n, err := d.dir.GetNode() return d.size, nil
if err != nil {
return 0, err
}
s, err := n.Size()
return int64(s), err
} }
type ufsFile struct { type ufsFile struct {
...@@ -134,17 +130,23 @@ func (f *ufsFile) Size() (int64, error) { ...@@ -134,17 +130,23 @@ func (f *ufsFile) Size() (int64, error) {
return int64(f.DagReader.Size()), nil 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) dir, err := uio.NewDirectoryFromNode(dserv, nd)
if err != nil { if err != nil {
return nil, err return nil, err
} }
size, err := nd.Size()
if err != nil {
return nil, err
}
return &ufsDirectory{ return &ufsDirectory{
ctx: ctx, ctx: ctx,
dserv: dserv, dserv: dserv,
dir: dir, dir: dir,
size: int64(size),
}, nil }, nil
} }
...@@ -156,7 +158,7 @@ func NewUnixfsFile(ctx context.Context, dserv ipld.DAGService, nd ipld.Node) (fi ...@@ -156,7 +158,7 @@ func NewUnixfsFile(ctx context.Context, dserv ipld.DAGService, nd ipld.Node) (fi
return nil, err return nil, err
} }
if fsn.IsDir() { if fsn.IsDir() {
return newUnixfsDir(ctx, dserv, nd) return newUnixfsDir(ctx, dserv, dn)
} }
if fsn.Type() == ft.TSymlink { if fsn.Type() == ft.TSymlink {
return files.NewLinkFile(string(fsn.Data()), nil), nil return files.NewLinkFile(string(fsn.Data()), nil), nil
......
...@@ -79,6 +79,6 @@ ...@@ -79,6 +79,6 @@
"license": "", "license": "",
"name": "go-unixfs", "name": "go-unixfs",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"", "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