From 91853fbb7ab45174e198b1eaf7da9113f7409efa Mon Sep 17 00:00:00 2001 From: Lucas Molas Date: Mon, 15 Nov 2021 21:07:50 -0300 Subject: [PATCH] support threshold based automatic sharding and unsharding of directories (#88) * feat: update go-unixfs and use built in automatic sharding and unsharding * chore: update deps Co-authored-by: Adin Schmahmann Co-authored-by: Gus Eggert This commit was moved from ipfs/go-mfs@e61420fa2f77775867cedd654709b6671270f58a --- mfs/dir.go | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/mfs/dir.go b/mfs/dir.go index 61f85d064..52b1b046d 100644 --- a/mfs/dir.go +++ b/mfs/dir.go @@ -128,7 +128,7 @@ func (d *Directory) localUpdate(c child) (*dag.ProtoNode, error) { // Update child entry in the underlying UnixFS directory. func (d *Directory) updateChild(c child) error { - err := d.addUnixFSChild(c) + err := d.unixfsDir.AddChild(d.ctx, c.Name, c.Node) if err != nil { return err } @@ -313,7 +313,7 @@ func (d *Directory) Mkdir(name string) (*Directory, error) { return nil, err } - err = d.addUnixFSChild(child{name, ndir}) + err = d.unixfsDir.AddChild(d.ctx, name, ndir) if err != nil { return nil, err } @@ -360,7 +360,7 @@ func (d *Directory) AddChild(name string, nd ipld.Node) error { return err } - err = d.addUnixFSChild(child{name, nd}) + err = d.unixfsDir.AddChild(d.ctx, name, nd) if err != nil { return err } @@ -369,29 +369,6 @@ func (d *Directory) AddChild(name string, nd ipld.Node) error { return nil } -// addUnixFSChild adds a child to the inner UnixFS directory -// and transitions to a HAMT implementation if needed. -func (d *Directory) addUnixFSChild(c child) error { - if uio.UseHAMTSharding { - // If the directory HAMT implementation is being used and this - // directory is actually a basic implementation switch it to HAMT. - if basicDir, ok := d.unixfsDir.(*uio.BasicDirectory); ok { - hamtDir, err := basicDir.SwitchToSharding(d.ctx) - if err != nil { - return err - } - d.unixfsDir = hamtDir - } - } - - err := d.unixfsDir.AddChild(d.ctx, c.Name, c.Node) - if err != nil { - return err - } - - return nil -} - func (d *Directory) sync() error { for name, entry := range d.entriesCache { nd, err := entry.GetNode()