Return CID from 'ipfs files flush'
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Mar 19, 2019 at 21:44 UTC
3d79102e4447cb22b9a02c7e55de650107d1b5b6
1 file changed
+19
-4
core/commands/files.go
+19
-4
@@ -347,7 +347,7 @@ var filesCpCmd = &cmds.Command{
347
}
348
349
if flush {
350
- err := mfs.FlushPath(req.Context, nd.FilesRoot, dst)
350
+ _, err := mfs.FlushPath(req.Context, nd.FilesRoot, dst)
351
if err != nil {
352
return fmt.Errorf("cp: cannot flush the created file %s: %s", dst, err)
353
}
@@ -649,7 +649,7 @@ Example:
649
650
err = mfs.Mv(nd.FilesRoot, src, dst)
651
if err == nil && flush {
652
- err = mfs.FlushPath(req.Context, nd.FilesRoot, "/")
652
+ _, err = mfs.FlushPath(req.Context, nd.FilesRoot, "/")
653
}
654
return err
655
},
@@ -856,6 +856,10 @@ Examples:
856
},
857
}
858
859
+type flushRes struct {
860
+ Cid string
861
+}
862
+
863
var filesFlushCmd = &cmds.Command{
864
Helptext: cmdkit.HelpText{
865
Tagline: "Flush a given path's data to disk.",
@@ -873,13 +877,24 @@ are run with the '--flush=false'.
877
return err
878
}
879
880
+ enc, err := cmdenv.GetCidEncoder(req)
881
+ if err != nil {
882
+ return err
883
+ }
884
+
885
path := "/"
886
if len(req.Arguments) > 0 {
887
path = req.Arguments[0]
888
}
889
881
- return mfs.FlushPath(req.Context, nd.FilesRoot, path)
890
+ n, err := mfs.FlushPath(req.Context, nd.FilesRoot, path)
891
+ if err != nil {
892
+ return err
893
+ }
894
+
895
+ return cmds.EmitOnce(res, &flushRes{enc.Encode(n.Cid())})
896
},
897
+ Type: flushRes{},
898
}
899
900
var filesChcidCmd = &cmds.Command{
@@ -916,7 +931,7 @@ Change the cid version or hash function of the root node of a given path.
931
932
err = updatePath(nd.FilesRoot, path, prefix)
933
if err == nil && flush {
919
- err = mfs.FlushPath(req.Context, nd.FilesRoot, path)
934
+ _, err = mfs.FlushPath(req.Context, nd.FilesRoot, path)
935
}
936
return err
937
},