From cb788ca2d2b68b9bf639764742a3a93854bf97d3 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Wed, 1 Mar 2023 03:17:15 -0500 Subject: [PATCH 1/2] feat: for file and directory iterators expose CIDs --- file/unixfile.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/file/unixfile.go b/file/unixfile.go index 82ee20a4d..b68492766 100644 --- a/file/unixfile.go +++ b/file/unixfile.go @@ -3,6 +3,7 @@ package unixfile import ( "context" "errors" + "github.com/ipfs/go-cid" ft "github.com/ipfs/go-unixfs" uio "github.com/ipfs/go-unixfs/io" @@ -122,14 +123,27 @@ func (d *ufsDirectory) Size() (int64, error) { return d.size, nil } +func (d *ufsDirectory) Cid() cid.Cid { + nd, err := d.dir.GetNode() + if err != nil { + return cid.Undef + } + return nd.Cid() +} + type ufsFile struct { uio.DagReader + nd ipld.Node } func (f *ufsFile) Size() (int64, error) { return int64(f.DagReader.Size()), nil } +func (f *ufsFile) Cid() cid.Cid { + return f.nd.Cid() +} + func newUnixfsDir(ctx context.Context, dserv ipld.DAGService, nd *dag.ProtoNode) (files.Directory, error) { dir, err := uio.NewDirectoryFromNode(dserv, nd) if err != nil { @@ -176,6 +190,7 @@ func NewUnixfsFile(ctx context.Context, dserv ipld.DAGService, nd ipld.Node) (fi return &ufsFile{ DagReader: dr, + nd: nd, }, nil } From 2acd046af3c685849ba3b0ce349a77907a917064 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Wed, 1 Mar 2023 03:26:57 -0500 Subject: [PATCH 2/2] add symlink wrapper for CID metadata --- file/unixfile.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/file/unixfile.go b/file/unixfile.go index b68492766..177a1fa71 100644 --- a/file/unixfile.go +++ b/file/unixfile.go @@ -144,6 +144,15 @@ func (f *ufsFile) Cid() cid.Cid { return f.nd.Cid() } +type ufsSymLink struct { + files.File + nd ipld.Node +} + +func (s *ufsSymLink) Cid() cid.Cid { + return s.nd.Cid() +} + func newUnixfsDir(ctx context.Context, dserv ipld.DAGService, nd *dag.ProtoNode) (files.Directory, error) { dir, err := uio.NewDirectoryFromNode(dserv, nd) if err != nil { @@ -175,7 +184,7 @@ func NewUnixfsFile(ctx context.Context, dserv ipld.DAGService, nd ipld.Node) (fi return newUnixfsDir(ctx, dserv, dn) } if fsn.Type() == ft.TSymlink { - return files.NewLinkFile(string(fsn.Data()), nil), nil + return &ufsSymLink{File: files.NewLinkFile(string(fsn.Data()), nil), nd: nd}, nil } case *dag.RawNode: