提交 3d79102e 作者: Łukasz Magiera

Return CID from 'ipfs files flush'

License: MIT
Signed-off-by: 's avatarŁukasz Magiera <magik6k@gmail.com>
上级 ca97b111
...@@ -347,7 +347,7 @@ var filesCpCmd = &cmds.Command{ ...@@ -347,7 +347,7 @@ var filesCpCmd = &cmds.Command{
} }
if flush { if flush {
err := mfs.FlushPath(req.Context, nd.FilesRoot, dst) _, err := mfs.FlushPath(req.Context, nd.FilesRoot, dst)
if err != nil { if err != nil {
return fmt.Errorf("cp: cannot flush the created file %s: %s", dst, err) return fmt.Errorf("cp: cannot flush the created file %s: %s", dst, err)
} }
...@@ -649,7 +649,7 @@ Example: ...@@ -649,7 +649,7 @@ Example:
err = mfs.Mv(nd.FilesRoot, src, dst) err = mfs.Mv(nd.FilesRoot, src, dst)
if err == nil && flush { if err == nil && flush {
err = mfs.FlushPath(req.Context, nd.FilesRoot, "/") _, err = mfs.FlushPath(req.Context, nd.FilesRoot, "/")
} }
return err return err
}, },
...@@ -856,6 +856,10 @@ Examples: ...@@ -856,6 +856,10 @@ Examples:
}, },
} }
type flushRes struct {
Cid string
}
var filesFlushCmd = &cmds.Command{ var filesFlushCmd = &cmds.Command{
Helptext: cmdkit.HelpText{ Helptext: cmdkit.HelpText{
Tagline: "Flush a given path's data to disk.", Tagline: "Flush a given path's data to disk.",
...@@ -873,13 +877,24 @@ are run with the '--flush=false'. ...@@ -873,13 +877,24 @@ are run with the '--flush=false'.
return err return err
} }
enc, err := cmdenv.GetCidEncoder(req)
if err != nil {
return err
}
path := "/" path := "/"
if len(req.Arguments) > 0 { if len(req.Arguments) > 0 {
path = req.Arguments[0] path = req.Arguments[0]
} }
return mfs.FlushPath(req.Context, nd.FilesRoot, path) n, err := mfs.FlushPath(req.Context, nd.FilesRoot, path)
if err != nil {
return err
}
return cmds.EmitOnce(res, &flushRes{enc.Encode(n.Cid())})
}, },
Type: flushRes{},
} }
var filesChcidCmd = &cmds.Command{ var filesChcidCmd = &cmds.Command{
...@@ -916,7 +931,7 @@ Change the cid version or hash function of the root node of a given path. ...@@ -916,7 +931,7 @@ Change the cid version or hash function of the root node of a given path.
err = updatePath(nd.FilesRoot, path, prefix) err = updatePath(nd.FilesRoot, path, prefix)
if err == nil && flush { if err == nil && flush {
err = mfs.FlushPath(req.Context, nd.FilesRoot, path) _, err = mfs.FlushPath(req.Context, nd.FilesRoot, path)
} }
return err return err
}, },
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论