From e9953972ed06b5df0da03d596889a40428af20e6 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 21 Jan 2019 19:56:18 -0800 Subject: [PATCH] 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 --- core/commands/files.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/core/commands/files.go b/core/commands/files.go index 102e0acc9cf..28d2aa0d75d 100644 --- a/core/commands/files.go +++ b/core/commands/files.go @@ -636,6 +636,8 @@ Example: return err } + flush, _ := req.Options[filesFlushOptionName].(bool) + src, err := checkPath(req.Arguments[0]) if err != nil { return err @@ -645,7 +647,11 @@ Example: return err } - return mfs.Mv(nd.FilesRoot, src, dst) + err = mfs.Mv(nd.FilesRoot, src, dst) + if err == nil && flush { + err = mfs.FlushPath(nd.FilesRoot, "/") + } + return err }, } @@ -908,11 +914,15 @@ Change the cid version or hash function of the root node of a given path. return err } - return updatePath(nd.FilesRoot, path, prefix, flush) + err = updatePath(nd.FilesRoot, path, prefix) + if err == nil && flush { + err = mfs.FlushPath(nd.FilesRoot, path) + } + return err }, } -func updatePath(rt *mfs.Root, pth string, builder cid.Builder, flush bool) error { +func updatePath(rt *mfs.Root, pth string, builder cid.Builder) error { if builder == nil { return nil } @@ -929,10 +939,6 @@ func updatePath(rt *mfs.Root, pth string, builder cid.Builder, flush bool) error return fmt.Errorf("can only update directories") } - if flush { - nd.Flush() - } - return nil }