Skip to content

Commit 27ae4fd

Browse files
authored
Merge pull request #6102 from ipfs/feat/mfs-flush-cid
Return CID from 'ipfs files flush'
2 parents 444f364 + 3d79102 commit 27ae4fd

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

core/commands/files.go

+19-4
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ var filesCpCmd = &cmds.Command{
347347
}
348348

349349
if flush {
350-
err := mfs.FlushPath(req.Context, nd.FilesRoot, dst)
350+
_, err := mfs.FlushPath(req.Context, nd.FilesRoot, dst)
351351
if err != nil {
352352
return fmt.Errorf("cp: cannot flush the created file %s: %s", dst, err)
353353
}
@@ -649,7 +649,7 @@ Example:
649649

650650
err = mfs.Mv(nd.FilesRoot, src, dst)
651651
if err == nil && flush {
652-
err = mfs.FlushPath(req.Context, nd.FilesRoot, "/")
652+
_, err = mfs.FlushPath(req.Context, nd.FilesRoot, "/")
653653
}
654654
return err
655655
},
@@ -856,6 +856,10 @@ Examples:
856856
},
857857
}
858858

859+
type flushRes struct {
860+
Cid string
861+
}
862+
859863
var filesFlushCmd = &cmds.Command{
860864
Helptext: cmdkit.HelpText{
861865
Tagline: "Flush a given path's data to disk.",
@@ -873,13 +877,24 @@ are run with the '--flush=false'.
873877
return err
874878
}
875879

880+
enc, err := cmdenv.GetCidEncoder(req)
881+
if err != nil {
882+
return err
883+
}
884+
876885
path := "/"
877886
if len(req.Arguments) > 0 {
878887
path = req.Arguments[0]
879888
}
880889

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())})
882896
},
897+
Type: flushRes{},
883898
}
884899

885900
var filesChcidCmd = &cmds.Command{
@@ -916,7 +931,7 @@ Change the cid version or hash function of the root node of a given path.
916931

917932
err = updatePath(nd.FilesRoot, path, prefix)
918933
if err == nil && flush {
919-
err = mfs.FlushPath(req.Context, nd.FilesRoot, path)
934+
_, err = mfs.FlushPath(req.Context, nd.FilesRoot, path)
920935
}
921936
return err
922937
},

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ require (
4949
github.com/ipfs/go-merkledag v0.0.2
5050
github.com/ipfs/go-metrics-interface v0.0.1
5151
github.com/ipfs/go-metrics-prometheus v0.0.1
52-
github.com/ipfs/go-mfs v0.0.3
52+
github.com/ipfs/go-mfs v0.0.4
5353
github.com/ipfs/go-path v0.0.2
5454
github.com/ipfs/go-unixfs v0.0.2
5555
github.com/ipfs/go-verifcid v0.0.1

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ github.com/ipfs/go-metrics-prometheus v0.0.1 h1:5iY3WO20WFSOErZyyYemHsbGm0V+a8YN
188188
github.com/ipfs/go-metrics-prometheus v0.0.1/go.mod h1:ELLU99AQQNi+zX6GCGm2lAgnzdSH3u5UVlCdqSXnEks=
189189
github.com/ipfs/go-mfs v0.0.3 h1:gFBlZw9DpZXaxqeto1H9uLkg+qzE8EVbCIVD2yuKUU4=
190190
github.com/ipfs/go-mfs v0.0.3/go.mod h1:rUT0dKNWkKa1T+MobpBL2zANn7p8Y6unXANC0PV2FLk=
191+
github.com/ipfs/go-mfs v0.0.4 h1:34qX5A7mQTYTkszSKIAFr+Y7BbvwVjHW9mzHDxSUqTo=
192+
github.com/ipfs/go-mfs v0.0.4/go.mod h1:rUT0dKNWkKa1T+MobpBL2zANn7p8Y6unXANC0PV2FLk=
191193
github.com/ipfs/go-path v0.0.1 h1:6UskTq8xYVs3zVnHjXDvoCqw22dKWK1BwD1cy1cuHyc=
192194
github.com/ipfs/go-path v0.0.1/go.mod h1:ztzG4iSBN2/CJa93rtHAv/I+mpK+BGALeUoJzhclhw0=
193195
github.com/ipfs/go-path v0.0.2 h1:Nm9g9GCo3XoSASPh2cGEW9eGPt8xh0QzA1VNO69NTMs=

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,9 @@
531531
},
532532
{
533533
"author": "hsanjuan",
534-
"hash": "QmUpYgeayfk3b83aYfNzVXwJJvyYsBrtKJtsnPfyjbgcgb",
534+
"hash": "QmX1nx1HZoyRKpp1d5L52kvcfqMbdbV6k4LFFrCEv7wnpH",
535535
"name": "go-mfs",
536-
"version": "0.1.51"
536+
"version": "0.1.52"
537537
},
538538
{
539539
"author": "kevina",

0 commit comments

Comments
 (0)