@cryptotaxi247 / kubo / commits / b22275fb6

Add global --cid-base option and enable it for most commands.

This does it on ther server side for most commands. This also adds a global --output-cidv1 option. License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>

Kevin Atkinson committed Nov 22, 2018 at 04:16 UTC b22275fb66222e4b5cfd7f87f9bae7cf33735995
28 files changed +796 -171
core/commands/add.go
+6 -1
@@ -174,6 +174,11 @@ You can now check what blocks have been created by:
174 return fmt.Errorf("unrecognized hash function: %s", strings.ToLower(hashFunStr))
175 }
176
177 + enc, err := cmdenv.GetCidEncoder(req)
178 + if err != nil {
179 + return err
180 + }
181 +
182 events := make(chan interface{}, adderOutChanSize)
183
184 opts := []options.UnixfsAddOption{
@@ -226,7 +231,7 @@ You can now check what blocks have been created by:
231
232 h := ""
233 if output.Path != nil {
229 - h = output.Path.Cid().String()
234 + h = enc.Encode(output.Path.Cid())
235 }
236
237 res.Emit(&AddEvent{
core/commands/bitswap.go
+10 -3
@@ -74,12 +74,15 @@ Print out all blocks currently on the bitswap wantlist for the local peer.`,
74 },
75 Encoders: cmds.EncoderMap{
76 cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *KeyList) error {
77 + enc, err := cmdenv.GetLowLevelCidEncoder(req)
78 + if err != nil {
79 + return err
80 + }
81 // sort the keys first
82 cidutil.Sort(out.Keys)
83 for _, key := range out.Keys {
80 - fmt.Fprintln(w, key)
84 + fmt.Fprintln(w, enc.Encode(key))
85 }
82 -
86 return nil
87 }),
88 },
@@ -115,6 +118,10 @@ var bitswapStatCmd = &cmds.Command{
118 },
119 Encoders: cmds.EncoderMap{
120 cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, s *bitswap.Stat) error {
121 + enc, err := cmdenv.GetLowLevelCidEncoder(req)
122 + if err != nil {
123 + return err
124 + }
125 fmt.Fprintln(w, "bitswap status")
126 fmt.Fprintf(w, "\tprovides buffer: %d / %d\n", s.ProvideBufLen, bitswap.HasBlockBufferSize)
127 fmt.Fprintf(w, "\tblocks received: %d\n", s.BlocksReceived)
@@ -125,7 +132,7 @@ var bitswapStatCmd = &cmds.Command{
132 fmt.Fprintf(w, "\tdup data received: %s\n", humanize.Bytes(s.DupDataReceived))
133 fmt.Fprintf(w, "\twantlist [%d keys]\n", len(s.Wantlist))
134 for _, k := range s.Wantlist {
128 - fmt.Fprintf(w, "\t\t%s\n", k.String())
135 + fmt.Fprintf(w, "\t\t%s\n", enc.Encode(k))
136 }
137 fmt.Fprintf(w, "\tpartners [%d]\n", len(s.Peers))
138 for _, p := range s.Peers {
core/commands/cmdenv/cidbase.go new
+98
@@ -0,0 +1,98 @@
1 +package cmdenv
2 +
3 +import (
4 + "errors"
5 +
6 + path "gx/ipfs/QmNYPETsdAu2uQ1k9q9S1jYEGURaLHV6cbYRSVFVRftpF8/go-path"
7 + cmds "gx/ipfs/QmWGm4AbZEbnmdgVTza52MSNpEmBdFVqzmAysRbjrRyGbH/go-ipfs-cmds"
8 + cidenc "gx/ipfs/QmdPQx9fvN5ExVwMhRmh7YpCQJzJrFhd1AjVBwJmRMFJeX/go-cidutil/cidenc"
9 + cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
10 + mbase "gx/ipfs/QmekxXDhCxCJRNuzmHreuaT3BsuJcsjcXWNrtV9C8DRHtd/go-multibase"
11 +)
12 +
13 +var OptionCidBase = cmdkit.StringOption("cid-base", "Multibase encoding used for version 1 CIDs in output.")
14 +var OptionOutputCidV1 = cmdkit.BoolOption("output-cidv1", "Upgrade CID version 0 to version 1 in output.")
15 +
16 +// GetCidEncoder processes the `cid-base` and `output-cidv1` options and
17 +// returns a encoder to use based on those parameters.
18 +func GetCidEncoder(req *cmds.Request) (cidenc.Encoder, error) {
19 + return getCidBase(req, true)
20 +}
21 +
22 +// GetLowLevelCidEncoder is like GetCidEncoder but meant to be used by
23 +// lower level commands. It differs from GetCidEncoder in that CIDv0
24 +// are not, by default, auto-upgraded to CIDv1.
25 +func GetLowLevelCidEncoder(req *cmds.Request) (cidenc.Encoder, error) {
26 + return getCidBase(req, false)
27 +}
28 +
29 +func getCidBase(req *cmds.Request, autoUpgrade bool) (cidenc.Encoder, error) {
30 + base, _ := req.Options["cid-base"].(string)
31 + upgrade, upgradeDefined := req.Options["output-cidv1"].(bool)
32 +
33 + e := cidenc.Default()
34 +
35 + if base != "" {
36 + var err error
37 + e.Base, err = mbase.EncoderByName(base)
38 + if err != nil {
39 + return e, err
40 + }
41 + if autoUpgrade {
42 + e.Upgrade = true
43 + }
44 + }
45 +
46 + if upgradeDefined {
47 + e.Upgrade = upgrade
48 + }
49 +
50 + return e, nil
51 +}
52 +
53 +// CidBaseDefined returns true if the `cid-base` option is specified
54 +// on the command line
55 +func CidBaseDefined(req *cmds.Request) bool {
56 + base, _ := req.Options["cid-base"].(string)
57 + return base != ""
58 +}
59 +
60 +// CidEncoderFromPath creates a new encoder that is influenced from
61 +// the encoded Cid in a Path. For CidV0 the multibase from the base
62 +// encoder is used and automatic upgrades are disabled. For CidV1 the
63 +// multibase from the CID is used and upgrades are eneabled. On error
64 +// the base encoder is returned. If you don't care about the error
65 +// condition, it is safe to ignore the error returned.
66 +func CidEncoderFromPath(enc cidenc.Encoder, p string) (cidenc.Encoder, error) {
67 + v, err := extractCidString(p)
68 + if err != nil {
69 + return enc, err
70 + }
71 + if cidVer(v) == 0 {
72 + return cidenc.Encoder{Base: enc.Base, Upgrade: false}, nil
73 + }
74 + e, err := mbase.NewEncoder(mbase.Encoding(v[0]))
75 + if err != nil {
76 + return enc, err
77 + }
78 + return cidenc.Encoder{Base: e, Upgrade: true}, nil
79 +}
80 +
81 +func extractCidString(str string) (string, error) {
82 + p, err := path.ParsePath(str)
83 + if err != nil {
84 + return "", err
85 + }
86 + segs := p.Segments()
87 + if segs[0] == "ipfs" || segs[0] == "ipld" {
88 + return segs[1], nil
89 + }
90 + return "", errors.New("no CID found")
91 +}
92 +
93 +func cidVer(v string) int {
94 + if len(v) == 46 && v[:2] == "Qm" {
95 + return 0
96 + }
97 + return 1
98 +}
core/commands/cmdenv/cidbase_test.go new
+31
@@ -0,0 +1,31 @@
1 +package cmdenv
2 +
3 +import (
4 + "testing"
5 +)
6 +
7 +func TestExtractCidString(t *testing.T) {
8 + test := func(path string, cid string) {
9 + res, err := extractCidString(path)
10 + if err != nil || res != cid {
11 + t.Errorf("extractCidString(%s) failed", path)
12 + }
13 + }
14 + testFailure := func(path string) {
15 + _, err := extractCidString(path)
16 + if err == nil {
17 + t.Errorf("extractCidString(%s) should of failed", path)
18 + }
19 + }
20 + p := "QmRqVG8VGdKZ7KARqR96MV7VNHgWvEQifk94br5HpURpfu"
21 + test(p, p)
22 + test("/ipfs/"+p, p)
23 + testFailure("/ipns/" + p)
24 +
25 + p = "zb2rhfkM4FjkMLaUnygwhuqkETzbYXnUDf1P9MSmdNjW1w1Lk"
26 + test(p, p)
27 + test("/ipfs/"+p, p)
28 + test("/ipld/"+p, p)
29 +
30 + testFailure("/ipfs")
31 +}
core/commands/dag/dag.go
+13 -2
@@ -144,7 +144,11 @@ into an object of the specified format.
144 Type: OutputObject{},
145 Encoders: cmds.EncoderMap{
146 cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *OutputObject) error {
147 - fmt.Fprintln(w, out.Cid.String())
147 + enc, err := cmdenv.GetLowLevelCidEncoder(req)
148 + if err != nil {
149 + return err
150 + }
151 + fmt.Fprintln(w, enc.Encode(out.Cid))
152 return nil
153 }),
154 },
@@ -227,7 +231,14 @@ var DagResolveCmd = &cmds.Command{
231 },
232 Encoders: cmds.EncoderMap{
233 cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *ResolveOutput) error {
230 - p := out.Cid.String()
234 + enc, err := cmdenv.GetLowLevelCidEncoder(req)
235 + if err != nil {
236 + return err
237 + }
238 + if !cmdenv.CidBaseDefined(req) {
239 + enc, _ = cmdenv.CidEncoderFromPath(enc, req.Arguments[0])
240 + }
241 + p := enc.Encode(out.Cid)
242 if out.RemPath != "" {
243 p = path.Join([]string{p, out.RemPath})
244 }
core/commands/files.go
+17 -6
@@ -17,13 +17,14 @@ import (
17 "gx/ipfs/QmP9eu5X5Ax8169jNWqAJcc42mdZgzLR1aKCEzqhNoBLKk/go-mfs"
18 "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
19 ft "gx/ipfs/QmQXze9tG878pa4Euya4rrDpyTNX3kQe4dhCaBzBozGgpe/go-unixfs"
20 - "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
20 + cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
21 dag "gx/ipfs/QmTQdH4848iTVCJmKXYyRiK72HufWTLYQQ8iN3JaQ8K1Hq/go-merkledag"
22 "gx/ipfs/QmWGm4AbZEbnmdgVTza52MSNpEmBdFVqzmAysRbjrRyGbH/go-ipfs-cmds"
23 bservice "gx/ipfs/QmYPZzd9VqmJDwxUnThfeSbV1Y5o53aVPDijTB7j7rS9Ep/go-blockservice"
24 "gx/ipfs/QmYZwey1thDTynSrvd6qQkX24UpTka6TFhQ2v569UpoqxD/go-ipfs-exchange-offline"
25 ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
26 logging "gx/ipfs/QmcuXC5cxs79ro2cUuHs4HQ2bkDLJUYokwL8aivcX6HW3C/go-log"
27 + cidenc "gx/ipfs/QmdPQx9fvN5ExVwMhRmh7YpCQJzJrFhd1AjVBwJmRMFJeX/go-cidutil/cidenc"
28 "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
29 mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash"
30 )
@@ -136,6 +137,11 @@ var filesStatCmd = &cmds.Command{
137
138 withLocal, _ := req.Options[filesWithLocalOptionName].(bool)
139
140 + enc, err := cmdenv.GetCidEncoder(req)
141 + if err != nil {
142 + return err
143 + }
144 +
145 var dagserv ipld.DAGService
146 if withLocal {
147 // an offline DAGService will not fetch from the network
@@ -152,7 +158,7 @@ var filesStatCmd = &cmds.Command{
158 return err
159 }
160
155 - o, err := statNode(nd)
161 + o, err := statNode(nd, enc)
162 if err != nil {
163 return err
164 }
@@ -217,7 +223,7 @@ func statGetFormatOptions(req *cmds.Request) (string, error) {
223 }
224 }
225
220 -func statNode(nd ipld.Node) (*statOutput, error) {
226 +func statNode(nd ipld.Node, enc cidenc.Encoder) (*statOutput, error) {
227 c := nd.Cid()
228
229 cumulsize, err := nd.Size()
@@ -243,7 +249,7 @@ func statNode(nd ipld.Node) (*statOutput, error) {
249 }
250
251 return &statOutput{
246 - Hash: c.String(),
252 + Hash: enc.Encode(c),
253 Blocks: len(nd.Links()),
254 Size: d.FileSize(),
255 CumulativeSize: cumulsize,
@@ -251,7 +257,7 @@ func statNode(nd ipld.Node) (*statOutput, error) {
257 }, nil
258 case *dag.RawNode:
259 return &statOutput{
254 - Hash: c.String(),
260 + Hash: enc.Encode(c),
261 Blocks: 0,
262 Size: cumulsize,
263 CumulativeSize: cumulsize,
@@ -433,6 +439,11 @@ Examples:
439
440 long, _ := req.Options[longOptionName].(bool)
441
442 + enc, err := cmdenv.GetCidEncoder(req)
443 + if err != nil {
444 + return err
445 + }
446 +
447 switch fsn := fsn.(type) {
448 case *mfs.Directory:
449 if !long {
@@ -470,7 +481,7 @@ Examples:
481 if err != nil {
482 return err
483 }
473 - out.Entries[0].Hash = nd.Cid().String()
484 + out.Entries[0].Hash = enc.Encode(nd.Cid())
485 }
486 return cmds.EmitOnce(res, out)
487 default:
core/commands/filestore.go
+26 -9
@@ -79,14 +79,20 @@ The output is:
79 return nil
80 },
81 PostRun: cmds.PostRunMap{
82 - cmds.CLI: streamResult(func(v interface{}, out io.Writer) nonFatalError {
83 - r := v.(*filestore.ListRes)
84 - if r.ErrorMsg != "" {
85 - return nonFatalError(r.ErrorMsg)
82 + cmds.CLI: func(res cmds.Response, re cmds.ResponseEmitter) error {
83 + enc, err := cmdenv.GetCidEncoder(res.Request())
84 + if err != nil {
85 + return err
86 }
87 - fmt.Fprintf(out, "%s\n", r.FormatLong())
88 - return ""
89 - }),
87 + return streamResult(func(v interface{}, out io.Writer) nonFatalError {
88 + r := v.(*filestore.ListRes)
89 + if r.ErrorMsg != "" {
90 + return nonFatalError(r.ErrorMsg)
91 + }
92 + fmt.Fprintf(out, "%s\n", r.FormatLong(enc.Encode))
93 + return ""
94 + })(res, re)
95 + },
96 },
97 Type: filestore.ListRes{},
98 }
@@ -151,6 +157,11 @@ For ERROR entries the error will also be printed to stderr.
157 },
158 PostRun: cmds.PostRunMap{
159 cmds.CLI: func(res cmds.Response, re cmds.ResponseEmitter) error {
160 + enc, err := cmdenv.GetCidEncoder(res.Request())
161 + if err != nil {
162 + return err
163 + }
164 +
165 for {
166 v, err := res.Next()
167 if err != nil {
@@ -168,7 +179,7 @@ For ERROR entries the error will also be printed to stderr.
179 if list.Status == filestore.StatusOtherError {
180 fmt.Fprintf(os.Stderr, "%s\n", list.ErrorMsg)
181 }
171 - fmt.Fprintf(os.Stdout, "%s %s\n", list.Status.Format(), list.FormatLong())
182 + fmt.Fprintf(os.Stdout, "%s %s\n", list.Status.Format(), list.FormatLong(enc.Encode))
183 }
184 },
185 },
@@ -184,6 +195,12 @@ var dupsFileStore = &cmds.Command{
195 if err != nil {
196 return err
197 }
198 +
199 + enc, err := cmdenv.GetCidEncoder(req)
200 + if err != nil {
201 + return err
202 + }
203 +
204 ch, err := fs.FileManager().AllKeysChan(req.Context)
205 if err != nil {
206 return err
@@ -195,7 +212,7 @@ var dupsFileStore = &cmds.Command{
212 return res.Emit(&RefWrapper{Err: err.Error()})
213 }
214 if have {
198 - if err := res.Emit(&RefWrapper{Ref: cid.String()}); err != nil {
215 + if err := res.Emit(&RefWrapper{Ref: enc.Encode(cid)}); err != nil {
216 return err
217 }
218 }
core/commands/ls.go
+10 -5
@@ -18,6 +18,7 @@ import (
18 blockservice "gx/ipfs/QmYPZzd9VqmJDwxUnThfeSbV1Y5o53aVPDijTB7j7rS9Ep/go-blockservice"
19 offline "gx/ipfs/QmYZwey1thDTynSrvd6qQkX24UpTka6TFhQ2v569UpoqxD/go-ipfs-exchange-offline"
20 ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
21 + cidenc "gx/ipfs/QmdPQx9fvN5ExVwMhRmh7YpCQJzJrFhd1AjVBwJmRMFJeX/go-cidutil/cidenc"
22 "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
23 )
24
@@ -94,9 +95,13 @@ The JSON output contains type information.
95 if err != nil {
96 return err
97 }
97 -
98 paths := req.Arguments
99
100 + enc, err := cmdenv.GetCidEncoder(req)
101 + if err != nil {
102 + return err
103 + }
104 +
105 var dagnodes []ipld.Node
106 for _, fpath := range paths {
107 p, err := iface.ParsePath(fpath)
@@ -134,7 +139,7 @@ The JSON output contains type information.
139 }
140 outputLinks := make([]LsLink, len(links))
141 for j, link := range links {
137 - lsLink, err := makeLsLink(req, dserv, resolveType, resolveSize, link)
142 + lsLink, err := makeLsLink(req, dserv, resolveType, resolveSize, link, enc)
143 if err != nil {
144 return err
145 }
@@ -168,7 +173,7 @@ The JSON output contains type information.
173 return linkResult.Err
174 }
175 link := linkResult.Link
171 - lsLink, err := makeLsLink(req, dserv, resolveType, resolveSize, link)
176 + lsLink, err := makeLsLink(req, dserv, resolveType, resolveSize, link, enc)
177 if err != nil {
178 return err
179 }
@@ -227,7 +232,7 @@ func makeDagNodeLinkResults(req *cmds.Request, dagnode ipld.Node) <-chan unixfs.
232 return linkResults
233 }
234
230 -func makeLsLink(req *cmds.Request, dserv ipld.DAGService, resolveType bool, resolveSize bool, link *ipld.Link) (*LsLink, error) {
235 +func makeLsLink(req *cmds.Request, dserv ipld.DAGService, resolveType bool, resolveSize bool, link *ipld.Link, enc cidenc.Encoder) (*LsLink, error) {
236 t := unixfspb.Data_DataType(-1)
237 var size uint64
238
@@ -260,7 +265,7 @@ func makeLsLink(req *cmds.Request, dserv ipld.DAGService, resolveType bool, reso
265 }
266 return &LsLink{
267 Name: link.Name,
263 - Hash: link.Cid.String(),
268 + Hash: enc.Encode(link.Cid),
269 Size: size,
270 Type: t,
271 }, nil
core/commands/object/object.go
+31 -6
@@ -119,6 +119,11 @@ multihash.
119 return err
120 }
121
122 + enc, err := cmdenv.GetLowLevelCidEncoder(req)
123 + if err != nil {
124 + return err
125 + }
126 +
127 path, err := coreiface.ParsePath(req.Arguments[0])
128 if err != nil {
129 return err
@@ -137,14 +142,14 @@ multihash.
142 outLinks := make([]Link, len(links))
143 for i, link := range links {
144 outLinks[i] = Link{
140 - Hash: link.Cid.String(),
145 + Hash: enc.Encode(link.Cid),
146 Name: link.Name,
147 Size: link.Size,
148 }
149 }
150
151 out := &Object{
147 - Hash: rp.Cid().String(),
152 + Hash: enc.Encode(rp.Cid()),
153 Links: outLinks,
154 }
155
@@ -209,6 +214,11 @@ Supported values are:
214 return err
215 }
216
217 + enc, err := cmdenv.GetLowLevelCidEncoder(req)
218 + if err != nil {
219 + return err
220 + }
221 +
222 path, err := coreiface.ParsePath(req.Arguments[0])
223 if err != nil {
224 return err
@@ -246,7 +256,7 @@ Supported values are:
256
257 for i, link := range nd.Links() {
258 node.Links[i] = Link{
249 - Hash: link.Cid.String(),
259 + Hash: enc.Encode(link.Cid),
260 Name: link.Name,
261 Size: link.Size,
262 }
@@ -299,6 +309,11 @@ var ObjectStatCmd = &cmds.Command{
309 return err
310 }
311
312 + enc, err := cmdenv.GetLowLevelCidEncoder(req)
313 + if err != nil {
314 + return err
315 + }
316 +
317 path, err := coreiface.ParsePath(req.Arguments[0])
318 if err != nil {
319 return err
@@ -310,7 +325,7 @@ var ObjectStatCmd = &cmds.Command{
325 }
326
327 oldStat := &ipld.NodeStat{
313 - Hash: ns.Cid.String(),
328 + Hash: enc.Encode(ns.Cid),
329 NumLinks: ns.NumLinks,
330 BlockSize: ns.BlockSize,
331 LinksSize: ns.LinksSize,
@@ -391,6 +406,11 @@ And then run:
406 return err
407 }
408
409 + enc, err := cmdenv.GetLowLevelCidEncoder(req)
410 + if err != nil {
411 + return err
412 + }
413 +
414 file, err := cmdenv.GetFileArg(req.Files.Entries())
415 if err != nil {
416 return err
@@ -419,7 +439,7 @@ And then run:
439 return err
440 }
441
422 - return cmds.EmitOnce(res, &Object{Hash: p.Cid().String()})
442 + return cmds.EmitOnce(res, &Object{Hash: enc.Encode(p.Cid())})
443 },
444 Encoders: cmds.EncoderMap{
445 cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *Object) error {
@@ -464,6 +484,11 @@ Available templates:
484 return err
485 }
486
487 + enc, err := cmdenv.GetLowLevelCidEncoder(req)
488 + if err != nil {
489 + return err
490 + }
491 +
492 template := "empty"
493 if len(req.Arguments) == 1 {
494 template = req.Arguments[0]
@@ -474,7 +499,7 @@ Available templates:
499 return err
500 }
501
477 - return cmds.EmitOnce(res, &Object{Hash: nd.Cid().String()})
502 + return cmds.EmitOnce(res, &Object{Hash: enc.Encode(nd.Cid())})
503 },
504 Encoders: cmds.EncoderMap{
505 cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *Object) error {
core/commands/pin.go
+45 -21
@@ -21,6 +21,7 @@ import (
21 "gx/ipfs/QmYMQuypUbgsdNHmuCBSUJV6wdQVsBHRivNAp3efHJwZJD/go-verifcid"
22 bserv "gx/ipfs/QmYPZzd9VqmJDwxUnThfeSbV1Y5o53aVPDijTB7j7rS9Ep/go-blockservice"
23 offline "gx/ipfs/QmYZwey1thDTynSrvd6qQkX24UpTka6TFhQ2v569UpoqxD/go-ipfs-exchange-offline"
24 + cidenc "gx/ipfs/QmdPQx9fvN5ExVwMhRmh7YpCQJzJrFhd1AjVBwJmRMFJeX/go-cidutil/cidenc"
25 cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
26 )
27
@@ -87,12 +88,17 @@ var addPinCmd = &cmds.Command{
88 return err
89 }
90
91 + enc, err := cmdenv.GetCidEncoder(req)
92 + if err != nil {
93 + return err
94 + }
95 +
96 if !showProgress {
97 added, err := corerepo.Pin(n.Pinning, api, req.Context, req.Arguments, recursive)
98 if err != nil {
99 return err
100 }
95 - return cmds.EmitOnce(res, &AddPinOutput{Pins: cidsToStrings(added)})
101 + return cmds.EmitOnce(res, &AddPinOutput{Pins: cidsToStrings(added, enc)})
102 }
103
104 v := new(dag.ProgressTracker)
@@ -124,7 +130,7 @@ var addPinCmd = &cmds.Command{
130 return err
131 }
132 }
127 - return res.Emit(&AddPinOutput{Pins: cidsToStrings(val.pins)})
133 + return res.Emit(&AddPinOutput{Pins: cidsToStrings(val.pins, enc)})
134 case <-ticker.C:
135 if err := res.Emit(&AddPinOutput{Progress: v.Value()}); err != nil {
136 return err
@@ -215,12 +221,17 @@ collected if needed. (By default, recursively. Use -r=false for direct pins.)
221 return err
222 }
223
224 + enc, err := cmdenv.GetCidEncoder(req)
225 + if err != nil {
226 + return err
227 + }
228 +
229 removed, err := corerepo.Unpin(n.Pinning, api, req.Context, req.Arguments, recursive)
230 if err != nil {
231 return err
232 }
233
223 - return cmds.EmitOnce(res, &PinOutput{cidsToStrings(removed)})
234 + return cmds.EmitOnce(res, &PinOutput{cidsToStrings(removed, enc)})
235 },
236 Encoders: cmds.EncoderMap{
237 cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *PinOutput) error {
@@ -311,19 +322,27 @@ Example:
322 return err
323 }
324
314 - var keys map[string]RefKeyObject
325 + enc, err := cmdenv.GetCidEncoder(req)
326 + if err != nil {
327 + return err
328 + }
329
330 + var keys map[cid.Cid]RefKeyObject
331 if len(req.Arguments) > 0 {
332 keys, err = pinLsKeys(req.Context, req.Arguments, typeStr, n, api)
333 } else {
334 keys, err = pinLsAll(req.Context, typeStr, n)
335 }
321 -
336 if err != nil {
337 return err
338 }
339
326 - return cmds.EmitOnce(res, &RefKeyList{Keys: keys})
340 + refKeys := make(map[string]RefKeyObject, len(keys))
341 + for k, v := range keys {
342 + refKeys[enc.Encode(k)] = v
343 + }
344 +
345 + return cmds.EmitOnce(res, &RefKeyList{Keys: refKeys})
346 },
347 Type: RefKeyList{},
348 Encoders: cmds.EncoderMap{
@@ -423,11 +442,16 @@ var verifyPinCmd = &cmds.Command{
442 return fmt.Errorf("the --verbose and --quiet options can not be used at the same time")
443 }
444
445 + enc, err := cmdenv.GetCidEncoder(req)
446 + if err != nil {
447 + return err
448 + }
449 +
450 opts := pinVerifyOpts{
451 explain: !quiet,
452 includeOk: verbose,
453 }
430 - out := pinVerify(req.Context, n, opts)
454 + out := pinVerify(req.Context, n, opts, enc)
455
456 return res.Emit(out)
457 },
@@ -455,14 +479,14 @@ type RefKeyList struct {
479 Keys map[string]RefKeyObject
480 }
481
458 -func pinLsKeys(ctx context.Context, args []string, typeStr string, n *core.IpfsNode, api iface.CoreAPI) (map[string]RefKeyObject, error) {
482 +func pinLsKeys(ctx context.Context, args []string, typeStr string, n *core.IpfsNode, api iface.CoreAPI) (map[cid.Cid]RefKeyObject, error) {
483
484 mode, ok := pin.StringToMode(typeStr)
485 if !ok {
486 return nil, fmt.Errorf("invalid pin mode '%s'", typeStr)
487 }
488
465 - keys := make(map[string]RefKeyObject)
489 + keys := make(map[cid.Cid]RefKeyObject)
490
491 for _, p := range args {
492 pth, err := iface.ParsePath(p)
@@ -489,7 +513,7 @@ func pinLsKeys(ctx context.Context, args []string, typeStr string, n *core.IpfsN
513 default:
514 pinType = "indirect through " + pinType
515 }
492 - keys[c.Cid().String()] = RefKeyObject{
516 + keys[c.Cid()] = RefKeyObject{
517 Type: pinType,
518 }
519 }
@@ -497,13 +521,13 @@ func pinLsKeys(ctx context.Context, args []string, typeStr string, n *core.IpfsN
521 return keys, nil
522 }
523
500 -func pinLsAll(ctx context.Context, typeStr string, n *core.IpfsNode) (map[string]RefKeyObject, error) {
524 +func pinLsAll(ctx context.Context, typeStr string, n *core.IpfsNode) (map[cid.Cid]RefKeyObject, error) {
525
502 - keys := make(map[string]RefKeyObject)
526 + keys := make(map[cid.Cid]RefKeyObject)
527
528 AddToResultKeys := func(keyList []cid.Cid, typeStr string) {
529 for _, c := range keyList {
506 - keys[c.String()] = RefKeyObject{
530 + keys[c] = RefKeyObject{
531 Type: typeStr,
532 }
533 }
@@ -552,8 +576,8 @@ type pinVerifyOpts struct {
576 includeOk bool
577 }
578
555 -func pinVerify(ctx context.Context, n *core.IpfsNode, opts pinVerifyOpts) <-chan interface{} {
556 - visited := make(map[string]PinStatus)
579 +func pinVerify(ctx context.Context, n *core.IpfsNode, opts pinVerifyOpts, enc cidenc.Encoder) <-chan interface{} {
580 + visited := make(map[cid.Cid]PinStatus)
581
582 bs := n.Blocks.Blockstore()
583 DAG := dag.NewDAGService(bserv.New(bs, offline.Exchange(bs)))
@@ -562,7 +586,7 @@ func pinVerify(ctx context.Context, n *core.IpfsNode, opts pinVerifyOpts) <-chan
586
587 var checkPin func(root cid.Cid) PinStatus
588 checkPin = func(root cid.Cid) PinStatus {
565 - key := root.String()
589 + key := root
590 if status, ok := visited[key]; ok {
591 return status
592 }
@@ -570,7 +594,7 @@ func pinVerify(ctx context.Context, n *core.IpfsNode, opts pinVerifyOpts) <-chan
594 if err := verifcid.ValidateCid(root); err != nil {
595 status := PinStatus{Ok: false}
596 if opts.explain {
573 - status.BadNodes = []BadNode{BadNode{Cid: key, Err: err.Error()}}
597 + status.BadNodes = []BadNode{BadNode{Cid: enc.Encode(key), Err: err.Error()}}
598 }
599 visited[key] = status
600 return status
@@ -580,7 +604,7 @@ func pinVerify(ctx context.Context, n *core.IpfsNode, opts pinVerifyOpts) <-chan
604 if err != nil {
605 status := PinStatus{Ok: false}
606 if opts.explain {
583 - status.BadNodes = []BadNode{BadNode{Cid: key, Err: err.Error()}}
607 + status.BadNodes = []BadNode{BadNode{Cid: enc.Encode(key), Err: err.Error()}}
608 }
609 visited[key] = status
610 return status
@@ -606,7 +630,7 @@ func pinVerify(ctx context.Context, n *core.IpfsNode, opts pinVerifyOpts) <-chan
630 pinStatus := checkPin(cid)
631 if !pinStatus.Ok || opts.includeOk {
632 select {
609 - case out <- &PinVerifyRes{cid.String(), pinStatus}:
633 + case out <- &PinVerifyRes{enc.Encode(cid), pinStatus}:
634 case <-ctx.Done():
635 return
636 }
@@ -629,10 +653,10 @@ func (r PinVerifyRes) Format(out io.Writer) {
653 }
654 }
655
632 -func cidsToStrings(cs []cid.Cid) []string {
656 +func cidsToStrings(cs []cid.Cid, enc cidenc.Encoder) []string {
657 out := make([]string, 0, len(cs))
658 for _, c := range cs {
635 - out = append(out, c.String())
659 + out = append(out, enc.Encode(c))
660 }
661 return out
662 }
core/commands/refs.go
+16 -10
@@ -14,6 +14,7 @@ import (
14 cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
15 cmds "gx/ipfs/QmWGm4AbZEbnmdgVTza52MSNpEmBdFVqzmAysRbjrRyGbH/go-ipfs-cmds"
16 ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
17 + cidenc "gx/ipfs/QmdPQx9fvN5ExVwMhRmh7YpCQJzJrFhd1AjVBwJmRMFJeX/go-cidutil/cidenc"
18 cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
19 )
20
@@ -79,6 +80,11 @@ NOTE: List all references recursively by using the flag '-r'.
80 return err
81 }
82
83 + enc, err := cmdenv.GetCidEncoder(req)
84 + if err != nil {
85 + return err
86 + }
87 +
88 unique, _ := req.Options[refsUniqueOptionName].(bool)
89 recursive, _ := req.Options[refsRecursiveOptionName].(bool)
90 maxDepth, _ := req.Options[refsMaxDepthOptionName].(int)
@@ -112,7 +118,7 @@ NOTE: List all references recursively by using the flag '-r'.
118 }
119
120 for _, o := range objs {
115 - if _, err := rw.WriteRefs(o); err != nil {
121 + if _, err := rw.WriteRefs(o, enc); err != nil {
122 if err := res.Emit(&RefWrapper{Err: err.Error()}); err != nil {
123 return err
124 }
@@ -194,11 +200,11 @@ type RefWriter struct {
200 }
201
202 // WriteRefs writes refs of the given object to the underlying writer.
197 -func (rw *RefWriter) WriteRefs(n ipld.Node) (int, error) {
198 - return rw.writeRefsRecursive(n, 0)
203 +func (rw *RefWriter) WriteRefs(n ipld.Node, enc cidenc.Encoder) (int, error) {
204 + return rw.writeRefsRecursive(n, 0, enc)
205 }
206
201 -func (rw *RefWriter) writeRefsRecursive(n ipld.Node, depth int) (int, error) {
207 +func (rw *RefWriter) writeRefsRecursive(n ipld.Node, depth int, enc cidenc.Encoder) (int, error) {
208 nc := n.Cid()
209
210 var count int
@@ -228,7 +234,7 @@ func (rw *RefWriter) writeRefsRecursive(n ipld.Node, depth int) (int, error) {
234
235 // Write this node if not done before (or !Unique)
236 if shouldWrite {
231 - if err := rw.WriteEdge(nc, lc, n.Links()[i].Name); err != nil {
237 + if err := rw.WriteEdge(nc, lc, n.Links()[i].Name, enc); err != nil {
238 return count, err
239 }
240 count++
@@ -240,7 +246,7 @@ func (rw *RefWriter) writeRefsRecursive(n ipld.Node, depth int) (int, error) {
246 // Note when !Unique, branches are always considered
247 // unexplored and only depth limits apply.
248 if goDeeper {
243 - c, err := rw.writeRefsRecursive(nd, depth+1)
249 + c, err := rw.writeRefsRecursive(nd, depth+1, enc)
250 count += c
251 if err != nil {
252 return count, err
@@ -309,7 +315,7 @@ func (rw *RefWriter) visit(c cid.Cid, depth int) (bool, bool) {
315 }
316
317 // Write one edge
312 -func (rw *RefWriter) WriteEdge(from, to cid.Cid, linkname string) error {
318 +func (rw *RefWriter) WriteEdge(from, to cid.Cid, linkname string, enc cidenc.Encoder) error {
319 if rw.Ctx != nil {
320 select {
321 case <-rw.Ctx.Done(): // just in case.
@@ -322,11 +328,11 @@ func (rw *RefWriter) WriteEdge(from, to cid.Cid, linkname string) error {
328 switch {
329 case rw.PrintFmt != "":
330 s = rw.PrintFmt
325 - s = strings.Replace(s, "<src>", from.String(), -1)
326 - s = strings.Replace(s, "<dst>", to.String(), -1)
331 + s = strings.Replace(s, "<src>", enc.Encode(from), -1)
332 + s = strings.Replace(s, "<dst>", enc.Encode(to), -1)
333 s = strings.Replace(s, "<linkname>", linkname, -1)
334 default:
329 - s += to.String()
335 + s += enc.Encode(to)
336 }
337
338 return rw.res.Emit(&RefWrapper{Ref: s})
core/commands/resolve.go
+9 -1
@@ -82,6 +82,14 @@ Resolve the value of an IPFS DAG path:
82 name := req.Arguments[0]
83 recursive, _ := req.Options[resolveRecursiveOptionName].(bool)
84
85 + enc, err := cmdenv.GetCidEncoder(req)
86 + if err != nil {
87 + return err
88 + }
89 + if !cmdenv.CidBaseDefined(req) {
90 + enc, _ = cmdenv.CidEncoderFromPath(enc, name)
91 + }
92 +
93 // the case when ipns is resolved step by step
94 if strings.HasPrefix(name, "/ipns/") && !recursive {
95 rc, rcok := req.Options[resolveDhtRecordCountOptionName].(uint)
@@ -128,7 +136,7 @@ Resolve the value of an IPFS DAG path:
136 return fmt.Errorf("found non-link at given path")
137 }
138
131 - return cmds.EmitOnce(res, &ncmd.ResolvedPath{Path: path.Path("/" + rp.Namespace() + "/" + rp.Cid().String())})
139 + return cmds.EmitOnce(res, &ncmd.ResolvedPath{Path: path.Path("/" + rp.Namespace() + "/" + enc.Encode(rp.Cid()))})
140 },
141 Encoders: cmds.EncoderMap{
142 cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, rp *ncmd.ResolvedPath) error {
core/commands/root.go
+4
@@ -3,6 +3,7 @@ package commands
3 import (
4 "errors"
5
6 + cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
7 dag "github.com/ipfs/go-ipfs/core/commands/dag"
8 name "github.com/ipfs/go-ipfs/core/commands/name"
9 ocmd "github.com/ipfs/go-ipfs/core/commands/object"
@@ -98,6 +99,9 @@ The CLI will exit with one of the following values:
99 cmdkit.StringOption(ApiOption, "Use a specific API instance (defaults to /ip4/127.0.0.1/tcp/5001)"),
100
101 // global options, added to every command
102 + cmdenv.OptionCidBase,
103 + cmdenv.OptionOutputCidV1,
104 +
105 cmds.OptionEncodingType,
106 cmds.OptionStreamChannels,
107 cmds.OptionTimeout,
core/commands/tar.go
+6 -1
@@ -43,6 +43,11 @@ represent it.
43 return err
44 }
45
46 + enc, err := cmdenv.GetCidEncoder(req)
47 + if err != nil {
48 + return err
49 + }
50 +
51 it := req.Files.Entries()
52 file, err := cmdenv.GetFileArg(it)
53 if err != nil {
@@ -58,7 +63,7 @@ represent it.
63
64 return cmds.EmitOnce(res, &AddEvent{
65 Name: it.Name(),
61 - Hash: c.String(),
66 + Hash: enc.Encode(c),
67 })
68 },
69 Type: AddEvent{},
core/commands/urlstore.go
+6 -1
@@ -77,6 +77,11 @@ time.
77 useTrickledag, _ := req.Options[trickleOptionName].(bool)
78 dopin, _ := req.Options[pinOptionName].(bool)
79
80 + enc, err := cmdenv.GetCidEncoder(req)
81 + if err != nil {
82 + return err
83 + }
84 +
85 hreq, err := http.NewRequest("GET", url, nil)
86 if err != nil {
87 return err
@@ -125,7 +130,7 @@ time.
130 }
131
132 return cmds.EmitOnce(res, &BlockStat{
128 - Key: c.String(),
133 + Key: enc.Encode(c),
134 Size: int(hres.ContentLength),
135 })
136 },
filestore/util.go
+6 -3
@@ -66,15 +66,18 @@ type ListRes struct {
66 Size uint64
67 }
68
69 -// FormatLong returns a human readable string for a ListRes object.
70 -func (r *ListRes) FormatLong() string {
69 +// FormatLong returns a human readable string for a ListRes object
70 +func (r *ListRes) FormatLong(enc func(cid.Cid) string) string {
71 + if enc == nil {
72 + enc = (cid.Cid).String
73 + }
74 switch {
75 case !r.Key.Defined():
76 return "<corrupt key>"
77 case r.FilePath == "":
78 return r.Key.String()
79 default:
77 - return fmt.Sprintf("%-50s %6d %s %d", r.Key, r.Size, r.FilePath, r.Offset)
80 + return fmt.Sprintf("%-50s %6d %s %d", enc(r.Key), r.Size, r.FilePath, r.Offset)
81 }
82 }
83
test/sharness/t0040-add-and-cat.sh
+49
@@ -272,6 +272,36 @@ test_add_cat_file() {
272 echo "added QmZQWnfcqJ6hNkkPvrY9Q5X39GP3jUnUbAV4AbmbbR3Cb1 test_current_dir" > expected
273 test_cmp expected actual
274 '
275 +
276 + # --cid-base=base32
277 +
278 + test_expect_success "ipfs add --cid-base=base32 succeeds" '
279 + echo "Hello Worlds!" >mountdir/hello.txt &&
280 + ipfs add --cid-base=base32 mountdir/hello.txt >actual
281 + '
282 +
283 + test_expect_success "ipfs add output looks good" '
284 + HASH="bafybeidpq7lcjx4w5c6yr4vuthzvlav54hgxsremwk73to5ferdc2rxhai" &&
285 + echo "added $HASH hello.txt" >expected &&
286 + test_cmp expected actual
287 + '
288 +
289 + test_expect_success "ipfs add --cid-base=base32 --only-hash succeeds" '
290 + ipfs add --cid-base=base32 --only-hash mountdir/hello.txt > oh_actual
291 + '
292 +
293 + test_expect_success "ipfs add --only-hash output looks good" '
294 + test_cmp expected oh_actual
295 + '
296 +
297 + test_expect_success "ipfs cat succeeds" '
298 + ipfs cat "$HASH" >actual
299 + '
300 +
301 + test_expect_success "ipfs cat output looks good" '
302 + echo "Hello Worlds!" >expected &&
303 + test_cmp expected actual
304 + '
305 }
306
307 test_add_cat_5MB() {
@@ -312,6 +342,25 @@ test_add_cat_5MB() {
342 test_expect_success FUSE "cat ipfs/bigfile looks good" '
343 test_cmp mountdir/bigfile actual
344 '
345 +
346 + test_expect_success "get base32 version of CID" '
347 + ipfs cid base32 $EXP_HASH > base32_cid &&
348 + BASE32_HASH=`cat base32_cid`
349 + '
350 +
351 + test_expect_success "ipfs add --cid-base=base32 bigfile' succeeds" '
352 + ipfs add $ADD_FLAGS --cid-base=base32 mountdir/bigfile >actual ||
353 + test_fsh cat daemon_err
354 + '
355 +
356 + test_expect_success "'ipfs add bigfile --cid-base=base32' output looks good" '
357 + echo "added $BASE32_HASH bigfile" >expected &&
358 + test_cmp expected actual
359 + '
360 +
361 + test_expect_success "'ipfs cat $BASE32_HASH' succeeds" '
362 + ipfs cat "$BASE32_HASH" >actual
363 + '
364 }
365
366 test_add_cat_raw() {
test/sharness/t0045-ls.sh
+9 -1
@@ -11,7 +11,6 @@ test_description="Test ls command"
11 test_init_ipfs
12
13 test_ls_cmd() {
14 -
14 test_expect_success "'ipfs add -r testData' succeeds" '
15 mkdir -p testData testData/d1 testData/d2 &&
16 echo "test" >testData/f1 &&
@@ -109,6 +108,15 @@ QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN 6 a
108 EOF
109 test_cmp expected_ls_headers actual_ls_headers
110 '
111 +
112 + test_expect_success "'ipfs ls --size=false --cid-base=base32 <three dir hashes>' succeeds" '
113 + ipfs ls --size=false --cid-base=base32 $(cid-fmt -v 1 -b base32 %s QmfNy183bXiRVyrhyWtq3TwHn79yHEkiAGFr18P7YNzESj QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss) >actual_ls_base32
114 + '
115 +
116 + test_expect_success "'ipfs ls --size=false --cid-base=base32 <three dir hashes>' output looks good" '
117 + cid-fmt -b base32 -v 1 --filter %s < expected_ls > expected_ls_base32
118 + test_cmp expected_ls_base32 actual_ls_base32
119 + '
120 }
121
122
test/sharness/t0051-object-data/mixed.json new
+5
@@ -0,0 +1,5 @@
1 +{"Data": "another",
2 + "Links": [
3 + {"Name": "some link", "Hash": "QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V", "Size": 8},
4 + {"Name": "inlined", "Hash": "z4CrgyEyhm4tAw1pgzQtNNuP7", "Size": 14}
5 +]}
test/sharness/t0051-object.sh
+52 -2
@@ -251,8 +251,6 @@ test_object_cmd() {
251 test_cmp expected actual
252 '
253
254 -
255 -
254 test_expect_success "object patch creation looks right" '
255 echo "QmPc73aWK9dgFBXe86P4PvQizHo9e5Qt7n7DAMXWuigFuG" > hash_exp &&
256 echo $N3 > hash_actual &&
@@ -350,6 +348,58 @@ test_object_cmd() {
348 ipfs object get $HASH > actual_data_append &&
349 test_cmp exp_data_append actual_data_append
350 '
351 +
352 + #
353 + # CidBase Tests
354 + #
355 +
356 + test_expect_success "'ipfs object put file.json --cid-base=base32' succeeds" '
357 + ipfs object put --cid-base=base32 ../t0051-object-data/testPut.json > actual_putOut
358 + '
359 +
360 + test_expect_success "'ipfs object put file.json --cid-base=base32' output looks good" '
361 + HASH="QmUTSAdDi2xsNkDtLqjFgQDMEn5di3Ab9eqbrt4gaiNbUD" &&
362 + printf "added $HASH\n" > expected_putOut &&
363 + test_cmp expected_putOut actual_putOut
364 + '
365 +
366 + test_expect_success "'ipfs object put file.json --cid-base=base32 --output-cidv1=true' succeeds" '
367 + ipfs object put --cid-base=base32 --output-cidv1=true ../t0051-object-data/testPut.json > actual_putOut
368 + '
369 +
370 + test_expect_success "'ipfs object put file.json --cid-base=base32 --output-cidv1=true' output looks good" '
371 + HASH=$(ipfs cid base32 "QmUTSAdDi2xsNkDtLqjFgQDMEn5di3Ab9eqbrt4gaiNbUD") &&
372 + printf "added $HASH\n" > expected_putOut &&
373 + test_cmp expected_putOut actual_putOut
374 + '
375 +
376 + test_expect_success "'insert json dag with both CidV0 and CidV1 links'" '
377 + MIXED=$(ipfs object put ../t0051-object-data/mixed.json -q) &&
378 + echo $MIXED
379 + '
380 +
381 + test_expect_success "ipfs object get then put creates identical object with --cid-base=base32" '
382 + ipfs object get --cid-base=base32 $MIXED > mixedv2.json &&
383 + MIXED2=$(ipfs object put -q mixedv2.json) &&
384 + echo "$MIXED =? $MIXED2" &&
385 + test "$MIXED" = "$MIXED2"
386 + '
387 +
388 + HASHv0=QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V
389 + HASHv1=z4CrgyEyhm4tAw1pgzQtNNuP7
390 +
391 + test_expect_success "ipfs object get with --cid-base=base32 uses base32 for CidV1 link only" '
392 + ipfs object get --cid-base=base32 $MIXED > mixed.actual &&
393 + grep -q $HASHv0 mixed.actual &&
394 + grep -q $(ipfs cid base32 $HASHv1) mixed.actual
395 + '
396 +
397 + test_expect_success "ipfs object links --cid-base=base32 --output-cidv1=true converts both links" '
398 + ipfs object links --cid-base=base32 --output-cidv1=true $MIXED | awk "{print \$1}" | sort > links.actual &&
399 + echo $(ipfs cid base32 $HASHv1) > links.expected
400 + echo $(ipfs cid base32 $HASHv0) >> links.expected
401 + test_cmp links.actual links.expected
402 + '
403 }
404
405 test_object_content_type() {
test/sharness/t0053-dag.sh
+62
@@ -26,6 +26,23 @@ test_expect_success "make an ipld object in json" '
26 '
27
28 test_dag_cmd() {
29 + test_expect_success "can add an ipld object using protobuf" '
30 + IPLDHASH=$(cat ipld_object | ipfs dag put -f protobuf)
31 + '
32 +
33 + test_expect_success "output looks correct" '
34 + EXPHASH="QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n"
35 + test $EXPHASH = $IPLDHASH
36 + '
37 +
38 + test_expect_success "can add an ipld object using protobuf and --cid=base=base32" '
39 + IPLDHASHb32=$(cat ipld_object | ipfs dag put -f protobuf --cid-base=base32)
40 + '
41 +
42 + test_expect_success "output looks correct (does not upgrade to CIDv1)" '
43 + test $EXPHASH = $IPLDHASHb32
44 + '
45 +
46 test_expect_success "can add an ipld object" '
47 IPLDHASH=$(cat ipld_object | ipfs dag put)
48 '
@@ -35,6 +52,14 @@ test_dag_cmd() {
52 test $EXPHASH = $IPLDHASH
53 '
54
55 + test_expect_success "can add an ipld object using --cid-base=base32" '
56 + IPLDHASHb32=$(cat ipld_object | ipfs dag put --cid-base=base32)
57 + '
58 +
59 + test_expect_success "output looks correct" '
60 + test $(ipfs cid base32 $EXPHASH) = $IPLDHASHb32
61 + '
62 +
63 test_expect_success "various path traversals work" '
64 ipfs cat $IPLDHASH/cats/0 > out1 &&
65 ipfs cat $IPLDHASH/cats/1/water > out2 &&
@@ -206,6 +231,43 @@ test_dag_cmd() {
231 test_cmp resolve_obj_exp resolve_obj &&
232 test_cmp resolve_data_exp resolve_data
233 '
234 +
235 + test_expect_success "get base32 version of hashes for testing" '
236 + HASHb32=$(ipfs cid base32 $HASH) &&
237 + NESTED_HASHb32=$(ipfs cid base32 $NESTED_HASH)
238 + '
239 +
240 + test_expect_success "dag resolve some things with --cid-base=base32" '
241 + ipfs dag resolve $HASH --cid-base=base32 > resolve_hash &&
242 + ipfs dag resolve ${HASH}/obj --cid-base=base32 > resolve_obj &&
243 + ipfs dag resolve ${HASH}/obj/data --cid-base=base32 > resolve_data
244 + '
245 +
246 + test_expect_success "dag resolve output looks good with --cid-base=base32" '
247 + printf $HASHb32 > resolve_hash_exp &&
248 + printf $NESTED_HASHb32 > resolve_obj_exp &&
249 + printf $NESTED_HASHb32/data > resolve_data_exp &&
250 +
251 + test_cmp resolve_hash_exp resolve_hash &&
252 + test_cmp resolve_obj_exp resolve_obj &&
253 + test_cmp resolve_data_exp resolve_data
254 + '
255 +
256 + test_expect_success "dag resolve some things with base32 hash" '
257 + ipfs dag resolve $HASHb32 > resolve_hash &&
258 + ipfs dag resolve ${HASHb32}/obj > resolve_obj &&
259 + ipfs dag resolve ${HASHb32}/obj/data > resolve_data
260 + '
261 +
262 + test_expect_success "dag resolve output looks good with base32 hash" '
263 + printf $HASHb32 > resolve_hash_exp &&
264 + printf $NESTED_HASHb32 > resolve_obj_exp &&
265 + printf $NESTED_HASHb32/data > resolve_data_exp &&
266 +
267 + test_cmp resolve_hash_exp resolve_hash &&
268 + test_cmp resolve_obj_exp resolve_obj &&
269 + test_cmp resolve_data_exp resolve_data
270 + '
271 }
272
273 # should work offline
test/sharness/t0085-pins.sh
+53 -16
@@ -11,15 +11,19 @@ test_description="Test ipfs pinning operations"
11
12 test_pins() {
13 EXTRA_ARGS=$1
14 + BASE=$2
15 + if [ -n "$BASE" ]; then
16 + BASE_ARGS="--cid-base=$BASE"
17 + fi
18
15 - test_expect_success "create some hashes" '
16 - HASH_A=$(echo "A" | ipfs add -q --pin=false) &&
17 - HASH_B=$(echo "B" | ipfs add -q --pin=false) &&
18 - HASH_C=$(echo "C" | ipfs add -q --pin=false) &&
19 - HASH_D=$(echo "D" | ipfs add -q --pin=false) &&
20 - HASH_E=$(echo "E" | ipfs add -q --pin=false) &&
21 - HASH_F=$(echo "F" | ipfs add -q --pin=false) &&
22 - HASH_G=$(echo "G" | ipfs add -q --pin=false)
19 + test_expect_success "create some hashes $BASE" '
20 + HASH_A=$(echo "A" | ipfs add $BASE_ARGS -q --pin=false) &&
21 + HASH_B=$(echo "B" | ipfs add $BASE_ARGS -q --pin=false) &&
22 + HASH_C=$(echo "C" | ipfs add $BASE_ARGS -q --pin=false) &&
23 + HASH_D=$(echo "D" | ipfs add $BASE_ARGS -q --pin=false) &&
24 + HASH_E=$(echo "E" | ipfs add $BASE_ARGS -q --pin=false) &&
25 + HASH_F=$(echo "F" | ipfs add $BASE_ARGS -q --pin=false) &&
26 + HASH_G=$(echo "G" | ipfs add $BASE_ARGS -q --pin=false)
27 '
28
29 test_expect_success "put all those hashes in a file" '
@@ -32,22 +36,53 @@ test_pins() {
36 echo $HASH_G >> hashes
37 '
38
39 + if [ -n "$BASE" ]; then
40 + test_expect_success "make sure hashes are in $BASE" '
41 + cat hashes | xargs cid-fmt %b | sort -u > actual
42 + echo base32 > expected
43 + test_cmp expected actual
44 + '
45 + fi
46 +
47 test_expect_success "'ipfs pin add $EXTRA_ARGS' via stdin" '
36 - cat hashes | ipfs pin add $EXTRA_ARGS
48 + cat hashes | ipfs pin add $EXTRA_ARGS $BASE_ARGS | tee actual
49 + '
50 +
51 + test_expect_success "'ipfs pin add $EXTRA_ARGS' output looks good" '
52 + sed -e "s/^/pinned /; s/$/ recursively/" hashes > expected &&
53 + test_cmp expected actual
54 '
55
56 test_expect_success "see if verify works" '
57 ipfs pin verify
58 '
59
43 - test_expect_success "see if verify --verbose works" '
44 - ipfs pin verify --verbose > verify_out &&
45 - test $(cat verify_out | wc -l) > 8
60 + test_expect_success "see if verify --verbose $BASE_ARGS works" '
61 + ipfs pin verify --verbose $BASE_ARGS > verify_out &&
62 + test $(cat verify_out | wc -l) -ge 7 &&
63 + test_should_contain "$HASH_A ok" verify_out &&
64 + test_should_contain "$HASH_B ok" verify_out &&
65 + test_should_contain "$HASH_C ok" verify_out &&
66 + test_should_contain "$HASH_D ok" verify_out &&
67 + test_should_contain "$HASH_E ok" verify_out &&
68 + test_should_contain "$HASH_F ok" verify_out &&
69 + test_should_contain "$HASH_G ok" verify_out
70 + '
71 +
72 + test_expect_success "ipfs pin ls $BASE_ARGS works" '
73 + ipfs pin ls $BASE_ARGS > ls_out &&
74 + test_should_contain "$HASH_A" ls_out &&
75 + test_should_contain "$HASH_B" ls_out &&
76 + test_should_contain "$HASH_C" ls_out &&
77 + test_should_contain "$HASH_D" ls_out &&
78 + test_should_contain "$HASH_E" ls_out &&
79 + test_should_contain "$HASH_F" ls_out &&
80 + test_should_contain "$HASH_G" ls_out
81 '
82
48 - test_expect_success "test pin ls hash" '
83 + test_expect_success "test pin ls $BASE_ARGS hash" '
84 echo $HASH_B | test_must_fail grep /ipfs && # just to be sure
50 - ipfs pin ls $HASH_B > ls_hash_out &&
85 + ipfs pin ls $BASE_ARGS $HASH_B > ls_hash_out &&
86 echo "$HASH_B recursive" > ls_hash_exp &&
87 test_cmp ls_hash_exp ls_hash_out
88 '
@@ -58,11 +93,11 @@ test_pins() {
93
94 test_expect_success "test pin update" '
95 ipfs pin add "$HASH_A" &&
61 - ipfs pin ls > before_update &&
96 + ipfs pin ls $BASE_ARGS | tee before_update &&
97 test_should_contain "$HASH_A" before_update &&
98 test_must_fail grep -q "$HASH_B" before_update &&
99 ipfs pin update --unpin=true "$HASH_A" "$HASH_B" &&
65 - ipfs pin ls > after_update &&
100 + ipfs pin ls $BASE_ARGS > after_update &&
101 test_must_fail grep -q "$HASH_A" after_update &&
102 test_should_contain "$HASH_B" after_update &&
103 ipfs pin rm "$HASH_B"
@@ -129,6 +164,7 @@ test_init_ipfs
164
165 test_pins
166 test_pins --progress
167 +test_pins '' base32
168
169 test_pins_error_reporting
170 test_pins_error_reporting --progress
@@ -142,6 +178,7 @@ test_launch_ipfs_daemon --offline
178
179 test_pins
180 test_pins --progress
181 +test_pins '' base32
182
183 test_pins_error_reporting
184 test_pins_error_reporting --progress
test/sharness/t0095-refs.sh
+65 -56
@@ -71,8 +71,12 @@ test_expect_success "create and add folders for refs" '
71 [[ "$root" == "$refsroot" ]]
72 '
73
74 -test_expect_success "ipfs refs -r" '
75 - cat <<EOF > expected.txt
74 +test_refs_output() {
75 + ARGS=$1
76 + FILTER=$2
77 +
78 + test_expect_success "ipfs refs $ARGS -r" '
79 + cat <<EOF | $FILTER > expected.txt
80 QmdytmR4wULMd3SLo6ePF4s3WcRHWcpnJZ7bHhoj3QB13v
81 QmNkQvpiyAEtbeLviC7kqfifYoK1GXPcsSxTpP1yS3ykLa
82 QmdytmR4wULMd3SLo6ePF4s3WcRHWcpnJZ7bHhoj3QB13v
@@ -87,13 +91,13 @@ QmSanP5DpxpqfDdS4yekHY1MqrVge47gtxQcp2e2yZ4UwS
91 QmSFxnK675wQ9Kc1uqWKyJUaNxvSc2BP5DbXCD3x93oq61
92 EOF
93
90 - ipfs refs -r $refsroot > refsr.txt
91 - test_cmp expected.txt refsr.txt
92 -'
94 + ipfs refs $ARGS -r $refsroot > refsr.txt
95 + test_cmp expected.txt refsr.txt
96 + '
97
94 -# Unique is like above but removing duplicates
95 -test_expect_success "ipfs refs -r --unique" '
96 - cat <<EOF > expected.txt
98 + # Unique is like above but removing duplicates
99 + test_expect_success "ipfs refs $ARGS -r --unique" '
100 + cat <<EOF | $FILTER > expected.txt
101 QmdytmR4wULMd3SLo6ePF4s3WcRHWcpnJZ7bHhoj3QB13v
102 QmNkQvpiyAEtbeLviC7kqfifYoK1GXPcsSxTpP1yS3ykLa
103 QmSanP5DpxpqfDdS4yekHY1MqrVge47gtxQcp2e2yZ4UwS
@@ -101,40 +105,40 @@ QmSFxnK675wQ9Kc1uqWKyJUaNxvSc2BP5DbXCD3x93oq61
105 QmXXazTjeNCKFnpW1D65vTKsTs8fbgkCWTv8Em4pdK2coH
106 EOF
107
104 - ipfs refs -r --unique $refsroot > refsr.txt
105 - test_cmp expected.txt refsr.txt
106 -'
108 + ipfs refs $ARGS -r --unique $refsroot > refsr.txt
109 + test_cmp expected.txt refsr.txt
110 + '
111
108 -# First level is 1.txt, B, C, D
109 -test_expect_success "ipfs refs" '
110 - cat <<EOF > expected.txt
112 + # First level is 1.txt, B, C, D
113 + test_expect_success "ipfs refs $ARGS" '
114 + cat <<EOF | $FILTER > expected.txt
115 QmdytmR4wULMd3SLo6ePF4s3WcRHWcpnJZ7bHhoj3QB13v
116 QmNkQvpiyAEtbeLviC7kqfifYoK1GXPcsSxTpP1yS3ykLa
117 QmXXazTjeNCKFnpW1D65vTKsTs8fbgkCWTv8Em4pdK2coH
118 QmSanP5DpxpqfDdS4yekHY1MqrVge47gtxQcp2e2yZ4UwS
119 EOF
116 - ipfs refs $refsroot > refs.txt
117 - test_cmp expected.txt refs.txt
118 -'
120 + ipfs refs $ARGS $refsroot > refs.txt
121 + test_cmp expected.txt refs.txt
122 + '
123
120 -# max-depth=0 should return an empty list
121 -test_expect_success "ipfs refs -r --max-depth=0" '
122 - cat <<EOF > expected.txt
124 + # max-depth=0 should return an empty list
125 + test_expect_success "ipfs refs $ARGS -r --max-depth=0" '
126 + cat <<EOF > expected.txt
127 EOF
124 - ipfs refs -r --max-depth=0 $refsroot > refs.txt
125 - test_cmp expected.txt refs.txt
126 -'
127 -
128 -# max-depth=1 should be equivalent to running without -r
129 -test_expect_success "ipfs refs -r --max-depth=1" '
130 - ipfs refs -r --max-depth=1 $refsroot > refsr.txt
131 - ipfs refs $refsroot > refs.txt
132 - test_cmp refsr.txt refs.txt
133 -'
134 -
135 -# We should see the depth limit engage at level 2
136 -test_expect_success "ipfs refs -r --max-depth=2" '
137 - cat <<EOF > expected.txt
128 + ipfs refs $ARGS -r --max-depth=0 $refsroot > refs.txt
129 + test_cmp expected.txt refs.txt
130 + '
131 +
132 + # max-depth=1 should be equivalent to running without -r
133 + test_expect_success "ipfs refs $ARGS -r --max-depth=1" '
134 + ipfs refs $ARGS -r --max-depth=1 $refsroot > refsr.txt
135 + ipfs refs $ARGS $refsroot > refs.txt
136 + test_cmp refsr.txt refs.txt
137 + '
138 +
139 + # We should see the depth limit engage at level 2
140 + test_expect_success "ipfs refs $ARGS -r --max-depth=2" '
141 + cat <<EOF | $FILTER > expected.txt
142 QmdytmR4wULMd3SLo6ePF4s3WcRHWcpnJZ7bHhoj3QB13v
143 QmNkQvpiyAEtbeLviC7kqfifYoK1GXPcsSxTpP1yS3ykLa
144 QmdytmR4wULMd3SLo6ePF4s3WcRHWcpnJZ7bHhoj3QB13v
@@ -144,33 +148,38 @@ QmNkQvpiyAEtbeLviC7kqfifYoK1GXPcsSxTpP1yS3ykLa
148 QmSanP5DpxpqfDdS4yekHY1MqrVge47gtxQcp2e2yZ4UwS
149 QmSFxnK675wQ9Kc1uqWKyJUaNxvSc2BP5DbXCD3x93oq61
150 EOF
147 - ipfs refs -r --max-depth=2 $refsroot > refsr.txt
148 - test_cmp refsr.txt expected.txt
149 -'
150 -
151 -# Here branch pruning and re-exploration come into place
152 -# At first it should see D at level 2 and don't go deeper.
153 -# But then after doing C it will see D at level 1 and go deeper
154 -# so that it outputs the hash for 2.txt (-q61).
155 -# We also see that C/B is pruned as it's been shown before.
156 -#
157 -# Excerpt from diagram above:
158 -#
159 -# L0- _______ A_________
160 -# / | \ \
161 -# L1- B C D 1.txt
162 -# / \ | |
163 -# L2- D 1.txt B 2.txt
164 -test_expect_success "ipfs refs -r --unique --max-depth=2" '
165 - cat <<EOF > expected.txt
151 + ipfs refs $ARGS -r --max-depth=2 $refsroot > refsr.txt
152 + test_cmp refsr.txt expected.txt
153 + '
154 +
155 + # Here branch pruning and re-exploration come into place
156 + # At first it should see D at level 2 and don't go deeper.
157 + # But then after doing C it will see D at level 1 and go deeper
158 + # so that it outputs the hash for 2.txt (-q61).
159 + # We also see that C/B is pruned as it's been shown before.
160 + #
161 + # Excerpt from diagram above:
162 + #
163 + # L0- _______ A_________
164 + # / | \ \
165 + # L1- B C D 1.txt
166 + # / \ | |
167 + # L2- D 1.txt B 2.txt
168 + test_expect_success "ipfs refs $ARGS -r --unique --max-depth=2" '
169 + cat <<EOF | $FILTER > expected.txt
170 QmdytmR4wULMd3SLo6ePF4s3WcRHWcpnJZ7bHhoj3QB13v
171 QmNkQvpiyAEtbeLviC7kqfifYoK1GXPcsSxTpP1yS3ykLa
172 QmSanP5DpxpqfDdS4yekHY1MqrVge47gtxQcp2e2yZ4UwS
173 QmXXazTjeNCKFnpW1D65vTKsTs8fbgkCWTv8Em4pdK2coH
174 QmSFxnK675wQ9Kc1uqWKyJUaNxvSc2BP5DbXCD3x93oq61
175 EOF
172 - ipfs refs -r --unique --max-depth=2 $refsroot > refsr.txt
173 - test_cmp refsr.txt expected.txt
174 -'
176 + ipfs refs $ARGS -r --unique --max-depth=2 $refsroot > refsr.txt
177 + test_cmp refsr.txt expected.txt
178 + '
179 +}
180 +
181 +test_refs_output '' 'cat'
182 +
183 +test_refs_output '--cid-base=base32' 'ipfs cid base32'
184
185 test_done
test/sharness/t0160-resolve.sh
+30 -2
@@ -12,6 +12,9 @@ test_expect_success "resolve: prepare files" '
12 a_hash=$(ipfs add -q -r a | tail -n1) &&
13 b_hash=$(ipfs add -q -r a/b | tail -n1) &&
14 c_hash=$(ipfs add -q -r a/b/c | tail -n1)
15 + a_hash_b32=$(cid-fmt -v 1 -b b %s $a_hash)
16 + b_hash_b32=$(cid-fmt -v 1 -b b %s $b_hash)
17 + c_hash_b32=$(cid-fmt -v 1 -b b %s $c_hash)
18 '
19
20 test_expect_success "resolve: prepare dag" '
@@ -45,9 +48,10 @@ test_resolve_setup_name_fail() {
48 test_resolve() {
49 src=$1
50 dst=$2
51 + extra=$3
52
53 test_expect_success "resolve succeeds: $src" '
50 - ipfs resolve -r "$src" >actual
54 + ipfs resolve $extra -r "$src" >actual
55 '
56
57 test_expect_success "resolved correctly: $src -> $dst" '
@@ -57,7 +61,6 @@ test_resolve() {
61 }
62
63 test_resolve_cmd() {
60 -
64 test_resolve "/ipfs/$a_hash" "/ipfs/$a_hash"
65 test_resolve "/ipfs/$a_hash/b" "/ipfs/$b_hash"
66 test_resolve "/ipfs/$a_hash/b/c" "/ipfs/$c_hash"
@@ -76,6 +79,30 @@ test_resolve_cmd() {
79 test_resolve "/ipns/$id_hash" "/ipfs/$c_hash"
80 }
81
82 +test_resolve_cmd_b32() {
83 + # no flags needed, base should be preserved
84 +
85 + test_resolve "/ipfs/$a_hash_b32" "/ipfs/$a_hash_b32"
86 + test_resolve "/ipfs/$a_hash_b32/b" "/ipfs/$b_hash_b32"
87 + test_resolve "/ipfs/$a_hash_b32/b/c" "/ipfs/$c_hash_b32"
88 + test_resolve "/ipfs/$b_hash_b32/c" "/ipfs/$c_hash_b32"
89 +
90 + # flags needed passed in path does not contain cid to derive base
91 +
92 + test_resolve_setup_name "/ipfs/$a_hash_b32"
93 + test_resolve "/ipns/$id_hash" "/ipfs/$a_hash_b32" --cid-base=base32
94 + test_resolve "/ipns/$id_hash/b" "/ipfs/$b_hash_b32" --cid-base=base32
95 + test_resolve "/ipns/$id_hash/b/c" "/ipfs/$c_hash_b32" --cid-base=base32
96 +
97 + test_resolve_setup_name "/ipfs/$b_hash_b32" --cid-base=base32
98 + test_resolve "/ipns/$id_hash" "/ipfs/$b_hash_b32" --cid-base=base32
99 + test_resolve "/ipns/$id_hash/c" "/ipfs/$c_hash_b32" --cid-base=base32
100 +
101 + test_resolve_setup_name "/ipfs/$c_hash_b32"
102 + test_resolve "/ipns/$id_hash" "/ipfs/$c_hash_b32" --cid-base=base32
103 +}
104 +
105 +
106 #todo remove this once the online resolve is fixed
107 test_resolve_fail() {
108 src=$1
@@ -117,6 +144,7 @@ test_resolve_cmd_fail() {
144
145 # should work offline
146 test_resolve_cmd
147 +test_resolve_cmd_b32
148
149 # should work online
150 test_launch_ipfs_daemon
test/sharness/t0210-tar.sh
+9
@@ -46,4 +46,13 @@ test_expect_success "files look right" '
46 [ -x foo/script ]
47 '
48
49 +test_expect_success "'ipfs tar add --cid-base=base32' succeeds" '
50 + ipfs tar add --cid-base=base32 files.tar > actual
51 +'
52 +
53 +test_expect_success "'ipfs tar add --cid-base=base32' has correct hash" '
54 + ipfs cid base32 $TAR_HASH > expected &&
55 + test_cmp expected actual
56 +'
57 +
58 test_done
test/sharness/t0250-files-api.sh
+19
@@ -202,6 +202,12 @@ test_files_api() {
202 test_cmp ls_l_expected ls_l_actual
203 '
204
205 + test_expect_success "file has correct hash and size listed with -l --cid-base=base32" '
206 + echo "file1 `cid-fmt -v 1 -b base32 %s $FILE1` 4" > ls_l_expected &&
207 + ipfs files ls --cid-base=base32 -l /cats/file1 > ls_l_actual &&
208 + test_cmp ls_l_expected ls_l_actual
209 + '
210 +
211 test_expect_success "file shows up with the correct name" '
212 echo "file1" > ls_l_expected &&
213 ipfs files ls /cats/file1 > ls_l_actual &&
@@ -221,6 +227,19 @@ test_files_api() {
227 test_cmp file1stat_expect file1stat_actual
228 '
229
230 + test_expect_success "can stat file with --cid-base=base32 $EXTRA" '
231 + ipfs files stat --cid-base=base32 /cats/file1 > file1stat_orig
232 + '
233 +
234 + test_expect_success "stat output looks good with --cid-base=base32" '
235 + grep -v CumulativeSize: file1stat_orig > file1stat_actual &&
236 + echo `cid-fmt -v 1 -b base32 %s $FILE1` > file1stat_expect &&
237 + echo "Size: 4" >> file1stat_expect &&
238 + echo "ChildBlocks: 0" >> file1stat_expect &&
239 + echo "Type: file" >> file1stat_expect &&
240 + test_cmp file1stat_expect file1stat_actual
241 + '
242 +
243 test_expect_success "can read file $EXTRA" '
244 ipfs files read /cats/file1 > file1out
245 '
test/sharness/t0271-filestore-utils.sh
+95 -25
@@ -63,40 +63,42 @@ EOF
63
64 sort < verify_expect_file_order > verify_expect_key_order
65
66 +IPFS_CMD="ipfs"
67 +
68 test_filestore_adds() {
67 - test_expect_success "nocopy add succeeds" '
68 - HASH=$(ipfs add --raw-leaves --nocopy -r -q somedir | tail -n1)
69 + test_expect_success "$IPFS_CMD add nocopy add succeeds" '
70 + HASH=$($IPFS_CMD add --raw-leaves --nocopy -r -q somedir | tail -n1)
71 '
72
73 test_expect_success "nocopy add has right hash" '
74 test "$HASH" = "$EXPHASH"
75 '
76
75 - test_expect_success "'ipfs filestore ls' output looks good'" '
76 - ipfs filestore ls | sort > ls_actual &&
77 + test_expect_success "'$IPFS_CMD filestore ls' output looks good'" '
78 + $IPFS_CMD filestore ls | sort > ls_actual &&
79 test_cmp ls_expect_key_order ls_actual
80 '
81
80 - test_expect_success "'ipfs filestore ls --file-order' output looks good'" '
81 - ipfs filestore ls --file-order > ls_actual &&
82 + test_expect_success "'$IPFS_CMD filestore ls --file-order' output looks good'" '
83 + $IPFS_CMD filestore ls --file-order > ls_actual &&
84 test_cmp ls_expect_file_order ls_actual
85 '
86
85 - test_expect_success "'ipfs filestore ls HASH' works" '
86 - ipfs filestore ls $FILE1_HASH > ls_actual &&
87 + test_expect_success "'$IPFS_CMD filestore ls HASH' works" '
88 + $IPFS_CMD filestore ls $FILE1_HASH > ls_actual &&
89 grep -q somedir/file1 ls_actual
90 '
91
92 test_expect_success "can retrieve multi-block file" '
91 - ipfs cat $FILE3_HASH > file3.data &&
93 + $IPFS_CMD cat $FILE3_HASH > file3.data &&
94 test_cmp somedir/file3 file3.data
95 '
96 }
97
98 # check that the filestore is in a clean state
99 test_filestore_state() {
98 - test_expect_success "ipfs filestore verify' output looks good'" '
99 - ipfs filestore verify | LC_ALL=C sort > verify_actual
100 + test_expect_success "$IPFS_CMD filestore verify' output looks good'" '
101 + $IPFS_CMD filestore verify | LC_ALL=C sort > verify_actual
102 test_cmp verify_expect_key_order verify_actual
103 '
104 }
@@ -104,13 +106,13 @@ test_filestore_state() {
106 test_filestore_verify() {
107 test_filestore_state
108
107 - test_expect_success "ipfs filestore verify --file-order' output looks good'" '
108 - ipfs filestore verify --file-order > verify_actual
109 + test_expect_success "$IPFS_CMD filestore verify --file-order' output looks good'" '
110 + $IPFS_CMD filestore verify --file-order > verify_actual
111 test_cmp verify_expect_file_order verify_actual
112 '
113
112 - test_expect_success "'ipfs filestore verify HASH' works" '
113 - ipfs filestore verify $FILE1_HASH > verify_actual &&
114 + test_expect_success "'$IPFS_CMD filestore verify HASH' works" '
115 + $IPFS_CMD filestore verify $FILE1_HASH > verify_actual &&
116 grep -q somedir/file1 verify_actual
117 '
118
@@ -119,11 +121,11 @@ test_filestore_verify() {
121 '
122
123 test_expect_success "can not retrieve block after backing file moved" '
122 - test_must_fail ipfs cat $FILE1_HASH
124 + test_must_fail $IPFS_CMD cat $FILE1_HASH
125 '
126
125 - test_expect_success "'ipfs filestore verify' shows file as missing" '
126 - ipfs filestore verify > verify_actual &&
127 + test_expect_success "'$IPFS_CMD filestore verify' shows file as missing" '
128 + $IPFS_CMD filestore verify > verify_actual &&
129 grep no-file verify_actual | grep -q somedir/file1
130 '
131
@@ -132,7 +134,7 @@ test_filestore_verify() {
134 '
135
136 test_expect_success "block okay now" '
135 - ipfs cat $FILE1_HASH > file1.data &&
137 + $IPFS_CMD cat $FILE1_HASH > file1.data &&
138 test_cmp somedir/file1 file1.data
139 '
140
@@ -141,11 +143,11 @@ test_filestore_verify() {
143 '
144
145 test_expect_success "can not retrieve block after backing file changed" '
144 - test_must_fail ipfs cat $FILE3_HASH
146 + test_must_fail $IPFS_CMD cat $FILE3_HASH
147 '
148
147 - test_expect_success "'ipfs filestore verify' shows file as changed" '
148 - ipfs filestore verify > verify_actual &&
149 + test_expect_success "'$IPFS_CMD filestore verify' shows file as changed" '
150 + $IPFS_CMD filestore verify > verify_actual &&
151 grep changed verify_actual | grep -q somedir/file3
152 '
153
@@ -157,9 +159,9 @@ test_filestore_dups() {
159 # make sure the filestore is in a clean state
160 test_filestore_state
161
160 - test_expect_success "'ipfs filestore dups'" '
161 - ipfs add --raw-leaves somedir/file1 &&
162 - ipfs filestore dups > dups_actual &&
162 + test_expect_success "'$IPFS_CMD filestore dups'" '
163 + $IPFS_CMD add --raw-leaves somedir/file1 &&
164 + $IPFS_CMD filestore dups > dups_actual &&
165 echo "$FILE1_HASH" > dups_expect
166 test_cmp dups_expect dups_actual
167 '
@@ -195,4 +197,72 @@ test_filestore_dups
197
198 test_kill_ipfs_daemon
199
200 +##
201 +## base32
202 +##
203 +
204 +EXPHASH="bafybeibva2uh4qpwjo2yr5g7m7nd5kfq64atydq77qdlrikh5uejwqdcbi"
205 +
206 +cat <<EOF > ls_expect_file_order
207 +bafkreicj3ezgtrh3euw2gyub6w3jydhnouqobxt7stbgtns3mv3iwv6bqq 1000 somedir/file1 0
208 +bafkreibxwxisv4cld6x76ybqbvf2uwbkoswjqt4hut46af6rps2twme7ey 10000 somedir/file2 0
209 +bafkreidntk6ciin24oez6yjz4b25fgwecncvi4ua4uhr2tdyenogpzpid4 262144 somedir/file3 0
210 +bafkreidwie26yauqbhpd2nhhhmod55irq3z372mh6gw4ikl2ifo34c5jra 262144 somedir/file3 262144
211 +bafkreib7piyesy3dr22sawmycdftrmpyt3z4tmhxrdig2zt5zdp7qwbuay 262144 somedir/file3 524288
212 +bafkreigxp5k3k6b3i5sldu4r3im74nfxmoptuuubcvq6rg632nfznskglu 213568 somedir/file3 786432
213 +EOF
214 +
215 +sort < ls_expect_file_order > ls_expect_key_order
216 +
217 +FILE1_HASH=bafkreicj3ezgtrh3euw2gyub6w3jydhnouqobxt7stbgtns3mv3iwv6bqq
218 +FILE2_HASH=bafkreibxwxisv4cld6x76ybqbvf2uwbkoswjqt4hut46af6rps2twme7ey
219 +FILE3_HASH=bafybeih24zygzr2orr5q62mjnbgmjwgj6rx3tp74pwcqsqth44rloncllq
220 +
221 +cat <<EOF > verify_expect_file_order
222 +ok bafkreicj3ezgtrh3euw2gyub6w3jydhnouqobxt7stbgtns3mv3iwv6bqq 1000 somedir/file1 0
223 +ok bafkreibxwxisv4cld6x76ybqbvf2uwbkoswjqt4hut46af6rps2twme7ey 10000 somedir/file2 0
224 +ok bafkreidntk6ciin24oez6yjz4b25fgwecncvi4ua4uhr2tdyenogpzpid4 262144 somedir/file3 0
225 +ok bafkreidwie26yauqbhpd2nhhhmod55irq3z372mh6gw4ikl2ifo34c5jra 262144 somedir/file3 262144
226 +ok bafkreib7piyesy3dr22sawmycdftrmpyt3z4tmhxrdig2zt5zdp7qwbuay 262144 somedir/file3 524288
227 +ok bafkreigxp5k3k6b3i5sldu4r3im74nfxmoptuuubcvq6rg632nfznskglu 213568 somedir/file3 786432
228 +EOF
229 +
230 +sort < verify_expect_file_order > verify_expect_key_order
231 +
232 +IPFS_CMD="ipfs --cid-base=base32"
233 +
234 +#
235 +# No daemon
236 +#
237 +
238 +test_init
239 +
240 +test_filestore_adds
241 +
242 +test_filestore_verify
243 +
244 +test_filestore_dups
245 +
246 +#
247 +# With daemon
248 +#
249 +
250 +test_init
251 +
252 +# must be in offline mode so tests that retrieve non-existent blocks
253 +# doesn't hang
254 +test_launch_ipfs_daemon --offline
255 +
256 +test_filestore_adds
257 +
258 +test_filestore_verify
259 +
260 +test_filestore_dups
261 +
262 +test_kill_ipfs_daemon
263 +
264 +test_done
265 +
266 +##
267 +
268 test_done
test/sharness/t0272-urlstore.sh
+14
@@ -150,6 +150,13 @@ test_expect_success "check that the trickle option works" '
150 test $HASHat = $HASHut
151 '
152
153 +test_expect_success "add files using gateway address via url store using --cid-base=base32" '
154 + HASH1a=$(ipfs add -q --trickle --raw-leaves=false file1) &&
155 + HASH2a=$(ipfs add -q --trickle --raw-leaves=false file2) &&
156 + HASH1b32=$(ipfs --cid-base=base32 urlstore add http://127.0.0.1:$GWAY_PORT/ipfs/$HASH1a) &&
157 + HASH2b32=$(ipfs --cid-base=base32 urlstore add http://127.0.0.1:$GWAY_PORT/ipfs/$HASH2a)
158 +'
159 +
160 test_kill_ipfs_daemon
161
162 test_expect_success "files can not be retrieved via the urlstore" '
@@ -167,4 +174,11 @@ test_expect_success "check that the hashes were correct" '
174 test $HASH3e = $HASH3
175 '
176
177 +test_expect_success "check that the base32 hashes were correct" '
178 + HASH1e32=$(ipfs cid base32 $HASH1e)
179 + HASH2e32=$(ipfs cid base32 $HASH2e)
180 + test $HASH1e32 = $HASH1b32 &&
181 + test $HASH2e32 = $HASH2b32
182 +'
183 +
184 test_done