@cryptotaxi247 / kubo / commits / e9953972e

mfs: make sure to flush after mv and chcid

We need to call `FlushPath` as `Flush` doesn't call `WaitPub` internally. The correct fix is to rework MFS such that Flush actually flushes but that's a larger project. License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>

Steven Allen committed Jan 21, 2019 at 19:56 UTC e9953972ed06b5df0da03d596889a40428af20e6
1 file changed +13 -7
core/commands/files.go
+13 -7
@@ -636,6 +636,8 @@ Example:
636 return err
637 }
638
639 + flush, _ := req.Options[filesFlushOptionName].(bool)
640 +
641 src, err := checkPath(req.Arguments[0])
642 if err != nil {
643 return err
@@ -645,7 +647,11 @@ Example:
647 return err
648 }
649
648 - return mfs.Mv(nd.FilesRoot, src, dst)
650 + err = mfs.Mv(nd.FilesRoot, src, dst)
651 + if err == nil && flush {
652 + err = mfs.FlushPath(nd.FilesRoot, "/")
653 + }
654 + return err
655 },
656 }
657
@@ -908,11 +914,15 @@ Change the cid version or hash function of the root node of a given path.
914 return err
915 }
916
911 - return updatePath(nd.FilesRoot, path, prefix, flush)
917 + err = updatePath(nd.FilesRoot, path, prefix)
918 + if err == nil && flush {
919 + err = mfs.FlushPath(nd.FilesRoot, path)
920 + }
921 + return err
922 },
923 }
924
915 -func updatePath(rt *mfs.Root, pth string, builder cid.Builder, flush bool) error {
925 +func updatePath(rt *mfs.Root, pth string, builder cid.Builder) error {
926 if builder == nil {
927 return nil
928 }
@@ -929,10 +939,6 @@ func updatePath(rt *mfs.Root, pth string, builder cid.Builder, flush bool) error
939 return fmt.Errorf("can only update directories")
940 }
941
932 - if flush {
933 - nd.Flush()
934 - }
935 -
942 return nil
943 }
944