Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2314b14

Browse files
committedNov 22, 2018
Add support for global --cid-base option to more commands.
Other related changes. License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
1 parent bc37725 commit 2314b14

19 files changed

+376
-174
lines changed
 

‎cmd/ipfs/main.go

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
oldcmds "github.com/ipfs/go-ipfs/commands"
2020
core "github.com/ipfs/go-ipfs/core"
2121
corecmds "github.com/ipfs/go-ipfs/core/commands"
22+
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
2223
corehttp "github.com/ipfs/go-ipfs/core/corehttp"
2324
loader "github.com/ipfs/go-ipfs/plugin/loader"
2425
repo "github.com/ipfs/go-ipfs/repo"
@@ -28,6 +29,7 @@ import (
2829
manet "gx/ipfs/QmQVUtnrNGtCRkCMpXgpApfzQjc8FDaDVxHqWH8cnZQeh5/go-multiaddr-net"
2930
ma "gx/ipfs/QmRKLtwMw131aK7ugC3G7ybpumMz78YrJe5dzneyindvG1/go-multiaddr"
3031
madns "gx/ipfs/QmT4zgnKCyZBpRyxzsvZqUjzUkMWLJ2pZCw7uk6M6Kto5m/go-multiaddr-dns"
32+
cidenc "gx/ipfs/QmWf8NwKFLbTBvAvZst3bYF7WEEetzxWyMhvQ885cj9MM8/go-cidutil/cidenc"
3133
osh "gx/ipfs/QmXuBJ7DR6k3rmUEKtvVMhwjmXDuJgXXPUt4LQXKBMsU93/go-os-helper"
3234
"gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
3335
"gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds/cli"
@@ -116,6 +118,12 @@ func mainRet() int {
116118
}
117119
log.Debugf("config path is %s", repoPath)
118120

121+
enc, err := cmdenv.ProcCidBase(req)
122+
if err != nil {
123+
return nil, err
124+
}
125+
cidenc.Default = enc
126+
119127
// this sets up the function that will initialize the node
120128
// this is so that we can construct the node lazily.
121129
return &oldcmds.Context{

‎core/commands/add.go

-5
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,6 @@ You can now check what blocks have been created by:
225225
outChan := make(chan interface{})
226226
req := res.Request()
227227

228-
err := cmdenv.ProcCidBaseClientSide(req)
229-
if err != nil {
230-
return err
231-
}
232-
233228
sizeFile, ok := req.Files.(files.SizeFile)
234229
if ok {
235230
// Could be slow.

‎core/commands/cmdenv/cidbase.go

+4-12
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ func ProcCidBase(req *cmds.Request) (cidenc.Encoder, error) {
2424
if err != nil {
2525
return e, err
2626
}
27-
if !upgradeDefined {
28-
e.Upgrade = true
29-
}
27+
e.Upgrade = true
3028
}
3129

3230
if upgradeDefined {
@@ -36,13 +34,7 @@ func ProcCidBase(req *cmds.Request) (cidenc.Encoder, error) {
3634
return e, nil
3735
}
3836

39-
// ProcCidBaseClientSide processes the `cid-base` and `output-cidv1`
40-
// options and sets the default encoder based on those options
41-
func ProcCidBaseClientSide(req *cmds.Request) error {
42-
enc, err := ProcCidBase(req)
43-
if err != nil {
44-
return err
45-
}
46-
cidenc.Default = enc
47-
return nil
37+
func CidBaseDefined(req *cmds.Request) bool {
38+
base, _ := req.Options["cid-base"].(string)
39+
return base != ""
4840
}

‎core/commands/filestore.go

+19-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
filestore "github.com/ipfs/go-ipfs/filestore"
1212

1313
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
14+
apicid "gx/ipfs/QmWf8NwKFLbTBvAvZst3bYF7WEEetzxWyMhvQ885cj9MM8/go-cidutil/apicid"
1415
cmds "gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
1516
"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
1617
)
@@ -175,6 +176,11 @@ For ERROR entries the error will also be printed to stderr.
175176
Type: filestore.ListRes{},
176177
}
177178

179+
type FilestoreDupsOutput struct {
180+
Ref apicid.Hash
181+
Err string
182+
}
183+
178184
var dupsFileStore = &cmds.Command{
179185
Helptext: cmdkit.HelpText{
180186
Tagline: "List blocks that are both in the filestore and standard block storage.",
@@ -192,19 +198,28 @@ var dupsFileStore = &cmds.Command{
192198
for cid := range ch {
193199
have, err := fs.MainBlockstore().Has(cid)
194200
if err != nil {
195-
return res.Emit(&RefWrapper{Err: err.Error()})
201+
return res.Emit(&FilestoreDupsOutput{Err: err.Error()})
196202
}
197203
if have {
198-
if err := res.Emit(&RefWrapper{Ref: cid.String()}); err != nil {
204+
if err := res.Emit(&FilestoreDupsOutput{Ref: apicid.FromCid(cid)}); err != nil {
199205
return err
200206
}
201207
}
202208
}
203209

204210
return nil
205211
},
206-
Encoders: refsEncoderMap,
207-
Type: RefWrapper{},
212+
Encoders: cmds.EncoderMap{
213+
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *FilestoreDupsOutput) error {
214+
if out.Err != "" {
215+
return fmt.Errorf(out.Err)
216+
}
217+
fmt.Fprintln(w, out.Ref)
218+
219+
return nil
220+
}),
221+
},
222+
Type: FilestoreDupsOutput{},
208223
}
209224

210225
func getFilestore(env cmds.Environment) (*core.IpfsNode, *filestore.Filestore, error) {

‎core/commands/ls.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
uio "gx/ipfs/QmUnHNqhSB1JgzVCxL1Kz3yb4bdyB4q1Z9AD5AUBVmt3fZ/go-unixfs/io"
1515
unixfspb "gx/ipfs/QmUnHNqhSB1JgzVCxL1Kz3yb4bdyB4q1Z9AD5AUBVmt3fZ/go-unixfs/pb"
1616
blockservice "gx/ipfs/QmVDTbzzTwnuBwNbJdhW3u7LoBQp46bezm9yp4z1RoEepM/go-blockservice"
17+
apicid "gx/ipfs/QmWf8NwKFLbTBvAvZst3bYF7WEEetzxWyMhvQ885cj9MM8/go-cidutil/apicid"
1718
offline "gx/ipfs/QmYZwey1thDTynSrvd6qQkX24UpTka6TFhQ2v569UpoqxD/go-ipfs-exchange-offline"
1819
cmds "gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
1920
merkledag "gx/ipfs/QmcGt25mrjuB2kKW2zhPbXVZNHc4yoTDQ65NA8m6auP2f1/go-merkledag"
@@ -23,9 +24,10 @@ import (
2324

2425
// LsLink contains printable data for a single ipld link in ls output
2526
type LsLink struct {
26-
Name, Hash string
27-
Size uint64
28-
Type unixfspb.Data_DataType
27+
Name string
28+
Hash apicid.Hash
29+
Size uint64
30+
Type unixfspb.Data_DataType
2931
}
3032

3133
// LsObject is an element of LsOutput
@@ -250,7 +252,7 @@ func makeLsLink(req *cmds.Request, dserv ipld.DAGService, resolve bool, link *ip
250252
}
251253
return &LsLink{
252254
Name: link.Name,
253-
Hash: link.Cid.String(),
255+
Hash: apicid.FromCid(link.Cid),
254256
Size: link.Size,
255257
Type: t,
256258
}, nil

‎core/commands/pin.go

+31-26
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717

1818
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
1919
bserv "gx/ipfs/QmVDTbzzTwnuBwNbJdhW3u7LoBQp46bezm9yp4z1RoEepM/go-blockservice"
20+
apicid "gx/ipfs/QmWf8NwKFLbTBvAvZst3bYF7WEEetzxWyMhvQ885cj9MM8/go-cidutil/apicid"
2021
"gx/ipfs/QmYMQuypUbgsdNHmuCBSUJV6wdQVsBHRivNAp3efHJwZJD/go-verifcid"
2122
offline "gx/ipfs/QmYZwey1thDTynSrvd6qQkX24UpTka6TFhQ2v569UpoqxD/go-ipfs-exchange-offline"
2223
cmds "gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
@@ -39,11 +40,11 @@ var PinCmd = &cmds.Command{
3940
}
4041

4142
type PinOutput struct {
42-
Pins []string
43+
Pins []apicid.Hash
4344
}
4445

4546
type AddPinOutput struct {
46-
Pins []string
47+
Pins []apicid.Hash
4748
Progress int `json:",omitempty"`
4849
}
4950

@@ -92,7 +93,7 @@ var addPinCmd = &cmds.Command{
9293
if err != nil {
9394
return err
9495
}
95-
return cmds.EmitOnce(res, &AddPinOutput{Pins: cidsToStrings(added)})
96+
return cmds.EmitOnce(res, &AddPinOutput{Pins: toAPICids(added)})
9697
}
9798

9899
v := new(dag.ProgressTracker)
@@ -124,7 +125,7 @@ var addPinCmd = &cmds.Command{
124125
return err
125126
}
126127
}
127-
return res.Emit(&AddPinOutput{Pins: cidsToStrings(val.pins)})
128+
return res.Emit(&AddPinOutput{Pins: toAPICids(val.pins)})
128129
case <-ticker.C:
129130
if err := res.Emit(&AddPinOutput{Progress: v.Value()}); err != nil {
130131
return err
@@ -220,7 +221,7 @@ collected if needed. (By default, recursively. Use -r=false for direct pins.)
220221
return err
221222
}
222223

223-
return cmds.EmitOnce(res, &PinOutput{cidsToStrings(removed)})
224+
return cmds.EmitOnce(res, &PinOutput{toAPICids(removed)})
224225
},
225226
Encoders: cmds.EncoderMap{
226227
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *PinOutput) error {
@@ -311,7 +312,7 @@ Example:
311312
return err
312313
}
313314

314-
var keys map[string]RefKeyObject
315+
var keys map[apicid.Hash]RefKeyObject
315316

316317
if len(req.Arguments) > 0 {
317318
keys, err = pinLsKeys(req.Context, req.Arguments, typeStr, n, api)
@@ -347,6 +348,10 @@ const (
347348
pinUnpinOptionName = "unpin"
348349
)
349350

351+
type UpdatePinOutput struct {
352+
Pins []string // really paths
353+
}
354+
350355
var updatePinCmd = &cmds.Command{
351356
Helptext: cmdkit.HelpText{
352357
Tagline: "Update a recursive pin",
@@ -364,7 +369,7 @@ new pin and removing the old one.
364369
Options: []cmdkit.Option{
365370
cmdkit.BoolOption(pinUnpinOptionName, "Remove the old pin.").WithDefault(true),
366371
},
367-
Type: PinOutput{},
372+
Type: UpdatePinOutput{},
368373
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
369374
api, err := cmdenv.GetApi(env)
370375
if err != nil {
@@ -388,10 +393,10 @@ new pin and removing the old one.
388393
return err
389394
}
390395

391-
return cmds.EmitOnce(res, &PinOutput{Pins: []string{from.String(), to.String()}})
396+
return cmds.EmitOnce(res, &UpdatePinOutput{Pins: []string{from.String(), to.String()}})
392397
},
393398
Encoders: cmds.EncoderMap{
394-
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *PinOutput) error {
399+
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *UpdatePinOutput) error {
395400
fmt.Fprintf(w, "updated %s to %s\n", out.Pins[0], out.Pins[1])
396401
return nil
397402
}),
@@ -452,17 +457,17 @@ type RefKeyObject struct {
452457
}
453458

454459
type RefKeyList struct {
455-
Keys map[string]RefKeyObject
460+
Keys map[apicid.Hash]RefKeyObject
456461
}
457462

458-
func pinLsKeys(ctx context.Context, args []string, typeStr string, n *core.IpfsNode, api iface.CoreAPI) (map[string]RefKeyObject, error) {
463+
func pinLsKeys(ctx context.Context, args []string, typeStr string, n *core.IpfsNode, api iface.CoreAPI) (map[apicid.Hash]RefKeyObject, error) {
459464

460465
mode, ok := pin.StringToMode(typeStr)
461466
if !ok {
462467
return nil, fmt.Errorf("invalid pin mode '%s'", typeStr)
463468
}
464469

465-
keys := make(map[string]RefKeyObject)
470+
keys := make(map[apicid.Hash]RefKeyObject)
466471

467472
for _, p := range args {
468473
pth, err := iface.ParsePath(p)
@@ -489,21 +494,21 @@ func pinLsKeys(ctx context.Context, args []string, typeStr string, n *core.IpfsN
489494
default:
490495
pinType = "indirect through " + pinType
491496
}
492-
keys[c.Cid().String()] = RefKeyObject{
497+
keys[apicid.FromCid(c.Cid())] = RefKeyObject{
493498
Type: pinType,
494499
}
495500
}
496501

497502
return keys, nil
498503
}
499504

500-
func pinLsAll(ctx context.Context, typeStr string, n *core.IpfsNode) (map[string]RefKeyObject, error) {
505+
func pinLsAll(ctx context.Context, typeStr string, n *core.IpfsNode) (map[apicid.Hash]RefKeyObject, error) {
501506

502-
keys := make(map[string]RefKeyObject)
507+
keys := make(map[apicid.Hash]RefKeyObject)
503508

504509
AddToResultKeys := func(keyList []cid.Cid, typeStr string) {
505510
for _, c := range keyList {
506-
keys[c.String()] = RefKeyObject{
511+
keys[apicid.FromCid(c)] = RefKeyObject{
507512
Type: typeStr,
508513
}
509514
}
@@ -531,7 +536,7 @@ func pinLsAll(ctx context.Context, typeStr string, n *core.IpfsNode) (map[string
531536

532537
// PinVerifyRes is the result returned for each pin checked in "pin verify"
533538
type PinVerifyRes struct {
534-
Cid string
539+
Cid apicid.Hash
535540
PinStatus
536541
}
537542

@@ -543,7 +548,7 @@ type PinStatus struct {
543548

544549
// BadNode is used in PinVerifyRes
545550
type BadNode struct {
546-
Cid string
551+
Cid apicid.Hash
547552
Err string
548553
}
549554

@@ -553,7 +558,7 @@ type pinVerifyOpts struct {
553558
}
554559

555560
func pinVerify(ctx context.Context, n *core.IpfsNode, opts pinVerifyOpts) <-chan interface{} {
556-
visited := make(map[string]PinStatus)
561+
visited := make(map[cid.Cid]PinStatus)
557562

558563
bs := n.Blocks.Blockstore()
559564
DAG := dag.NewDAGService(bserv.New(bs, offline.Exchange(bs)))
@@ -562,15 +567,15 @@ func pinVerify(ctx context.Context, n *core.IpfsNode, opts pinVerifyOpts) <-chan
562567

563568
var checkPin func(root cid.Cid) PinStatus
564569
checkPin = func(root cid.Cid) PinStatus {
565-
key := root.String()
570+
key := root
566571
if status, ok := visited[key]; ok {
567572
return status
568573
}
569574

570575
if err := verifcid.ValidateCid(root); err != nil {
571576
status := PinStatus{Ok: false}
572577
if opts.explain {
573-
status.BadNodes = []BadNode{BadNode{Cid: key, Err: err.Error()}}
578+
status.BadNodes = []BadNode{BadNode{Cid: apicid.FromCid(key), Err: err.Error()}}
574579
}
575580
visited[key] = status
576581
return status
@@ -580,7 +585,7 @@ func pinVerify(ctx context.Context, n *core.IpfsNode, opts pinVerifyOpts) <-chan
580585
if err != nil {
581586
status := PinStatus{Ok: false}
582587
if opts.explain {
583-
status.BadNodes = []BadNode{BadNode{Cid: key, Err: err.Error()}}
588+
status.BadNodes = []BadNode{BadNode{Cid: apicid.FromCid(key), Err: err.Error()}}
584589
}
585590
visited[key] = status
586591
return status
@@ -606,7 +611,7 @@ func pinVerify(ctx context.Context, n *core.IpfsNode, opts pinVerifyOpts) <-chan
606611
pinStatus := checkPin(cid)
607612
if !pinStatus.Ok || opts.includeOk {
608613
select {
609-
case out <- &PinVerifyRes{cid.String(), pinStatus}:
614+
case out <- &PinVerifyRes{apicid.FromCid(cid), pinStatus}:
610615
case <-ctx.Done():
611616
return
612617
}
@@ -629,10 +634,10 @@ func (r PinVerifyRes) Format(out io.Writer) {
629634
}
630635
}
631636

632-
func cidsToStrings(cs []cid.Cid) []string {
633-
out := make([]string, 0, len(cs))
637+
func toAPICids(cs []cid.Cid) []apicid.Hash {
638+
out := make([]apicid.Hash, 0, len(cs))
634639
for _, c := range cs {
635-
out = append(out, c.String())
640+
out = append(out, apicid.FromCid(c))
636641
}
637642
return out
638643
}

‎core/commands/refs.go

+16-10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
1414
path "gx/ipfs/QmVi2uUygezqaMTqs3Yzt5FcZFHJoYD4B7jQ2BELjj7ZuY/go-path"
15+
cidenc "gx/ipfs/QmWf8NwKFLbTBvAvZst3bYF7WEEetzxWyMhvQ885cj9MM8/go-cidutil/cidenc"
1516
cmds "gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
1617
ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
1718
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
@@ -79,6 +80,11 @@ NOTE: List all references recursively by using the flag '-r'.
7980
return err
8081
}
8182

83+
enc, err := cmdenv.ProcCidBase(req)
84+
if err != nil {
85+
return err
86+
}
87+
8288
unique, _ := req.Options[refsUniqueOptionName].(bool)
8389
recursive, _ := req.Options[refsRecursiveOptionName].(bool)
8490
maxDepth, _ := req.Options[refsMaxDepthOptionName].(int)
@@ -112,7 +118,7 @@ NOTE: List all references recursively by using the flag '-r'.
112118
}
113119

114120
for _, o := range objs {
115-
if _, err := rw.WriteRefs(o); err != nil {
121+
if _, err := rw.WriteRefs(o, enc); err != nil {
116122
if err := res.Emit(&RefWrapper{Err: err.Error()}); err != nil {
117123
return err
118124
}
@@ -194,11 +200,11 @@ type RefWriter struct {
194200
}
195201

196202
// 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.Interface) (int, error) {
204+
return rw.writeRefsRecursive(n, 0, enc)
199205
}
200206

201-
func (rw *RefWriter) writeRefsRecursive(n ipld.Node, depth int) (int, error) {
207+
func (rw *RefWriter) writeRefsRecursive(n ipld.Node, depth int, enc cidenc.Interface) (int, error) {
202208
nc := n.Cid()
203209

204210
var count int
@@ -228,7 +234,7 @@ func (rw *RefWriter) writeRefsRecursive(n ipld.Node, depth int) (int, error) {
228234

229235
// Write this node if not done before (or !Unique)
230236
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 {
232238
return count, err
233239
}
234240
count++
@@ -240,7 +246,7 @@ func (rw *RefWriter) writeRefsRecursive(n ipld.Node, depth int) (int, error) {
240246
// Note when !Unique, branches are always considered
241247
// unexplored and only depth limits apply.
242248
if goDeeper {
243-
c, err := rw.writeRefsRecursive(nd, depth+1)
249+
c, err := rw.writeRefsRecursive(nd, depth+1, enc)
244250
count += c
245251
if err != nil {
246252
return count, err
@@ -309,7 +315,7 @@ func (rw *RefWriter) visit(c cid.Cid, depth int) (bool, bool) {
309315
}
310316

311317
// 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.Interface) error {
313319
if rw.Ctx != nil {
314320
select {
315321
case <-rw.Ctx.Done(): // just in case.
@@ -322,11 +328,11 @@ func (rw *RefWriter) WriteEdge(from, to cid.Cid, linkname string) error {
322328
switch {
323329
case rw.PrintFmt != "":
324330
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)
327333
s = strings.Replace(s, "<linkname>", linkname, -1)
328334
default:
329-
s += to.String()
335+
s += enc.Encode(to)
330336
}
331337

332338
return rw.res.Emit(&RefWrapper{Ref: s})

‎core/commands/resolve.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
nsopts "github.com/ipfs/go-ipfs/namesys/opts"
1616
path "gx/ipfs/QmVi2uUygezqaMTqs3Yzt5FcZFHJoYD4B7jQ2BELjj7ZuY/go-path"
1717

18+
cidenc "gx/ipfs/QmWf8NwKFLbTBvAvZst3bYF7WEEetzxWyMhvQ885cj9MM8/go-cidutil/cidenc"
1819
cmds "gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
1920
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
2021
)
@@ -94,6 +95,14 @@ Resolve the value of an IPFS DAG path:
9495
name := req.Arguments[0]
9596
recursive, _ := req.Options[resolveRecursiveOptionName].(bool)
9697

98+
enc, err := cmdenv.ProcCidBase(req)
99+
if err != nil {
100+
return err
101+
}
102+
if !cmdenv.CidBaseDefined(req) {
103+
enc, _ = cidenc.FromPath(enc, name)
104+
}
105+
97106
// the case when ipns is resolved step by step
98107
if strings.HasPrefix(name, "/ipns/") && !recursive {
99108
rc, rcok := req.Options[resolveDhtRecordCountOptionName].(uint)
@@ -140,7 +149,7 @@ Resolve the value of an IPFS DAG path:
140149
return fmt.Errorf("found non-link at given path")
141150
}
142151

143-
return cmds.EmitOnce(res, &ncmd.ResolvedPath{Path: path.Path("/" + rp.Namespace() + "/" + rp.Cid().String())})
152+
return cmds.EmitOnce(res, &ncmd.ResolvedPath{Path: path.Path("/" + rp.Namespace() + "/" + enc.Encode(rp.Cid()))})
144153
},
145154
Encoders: cmds.EncoderMap{
146155
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, rp *ncmd.ResolvedPath) error {

‎core/commands/tar.go

-5
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ represent it.
6666
Type: coreiface.AddEvent{},
6767
Encoders: cmds.EncoderMap{
6868
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *coreiface.AddEvent) error {
69-
err := cmdenv.ProcCidBaseClientSide(req)
70-
if err != nil {
71-
return err
72-
}
73-
7469
fmt.Fprintln(w, out.Hash)
7570
return nil
7671
}),

‎core/commands/urlstore.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
balanced "gx/ipfs/QmUnHNqhSB1JgzVCxL1Kz3yb4bdyB4q1Z9AD5AUBVmt3fZ/go-unixfs/importer/balanced"
1414
ihelper "gx/ipfs/QmUnHNqhSB1JgzVCxL1Kz3yb4bdyB4q1Z9AD5AUBVmt3fZ/go-unixfs/importer/helpers"
1515
trickle "gx/ipfs/QmUnHNqhSB1JgzVCxL1Kz3yb4bdyB4q1Z9AD5AUBVmt3fZ/go-unixfs/importer/trickle"
16+
apicid "gx/ipfs/QmWf8NwKFLbTBvAvZst3bYF7WEEetzxWyMhvQ885cj9MM8/go-cidutil/apicid"
1617
cmds "gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
1718
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
1819
mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash"
@@ -24,6 +25,11 @@ var urlStoreCmd = &cmds.Command{
2425
},
2526
}
2627

28+
type UrlstoreAddOutput struct {
29+
Key apicid.Hash
30+
Size int
31+
}
32+
2733
var urlAdd = &cmds.Command{
2834
Helptext: cmdkit.HelpText{
2935
Tagline: "Add URL via urlstore.",
@@ -50,7 +56,7 @@ time.
5056
Arguments: []cmdkit.Argument{
5157
cmdkit.StringArg("url", true, false, "URL to add to IPFS"),
5258
},
53-
Type: &BlockStat{},
59+
Type: &UrlstoreAddOutput{},
5460

5561
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
5662
url := req.Arguments[0]
@@ -107,13 +113,13 @@ time.
107113
return err
108114
}
109115

110-
return cmds.EmitOnce(res, &BlockStat{
111-
Key: root.Cid().String(),
116+
return cmds.EmitOnce(res, &UrlstoreAddOutput{
117+
Key: apicid.FromCid(root.Cid()),
112118
Size: int(hres.ContentLength),
113119
})
114120
},
115121
Encoders: cmds.EncoderMap{
116-
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, bs *BlockStat) error {
122+
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, bs *UrlstoreAddOutput) error {
117123
_, err := fmt.Fprintln(w, bs.Key)
118124
return err
119125
}),

‎core/coreapi/unixfs_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ import (
2525

2626
ci "gx/ipfs/QmNiJiXwWE3kRhZrC5ej3kSjWHm337pYfhjLGSCDNKJP2s/go-libp2p-crypto"
2727
pstore "gx/ipfs/QmQAGG1zxfePqj2t7bLxyN8AFccZ889DDR9Gn8kVLDrGZo/go-libp2p-peerstore"
28+
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
2829
cbor "gx/ipfs/QmRoARq3nkUb13HSKZGepCZSWe5GrVPwx7xURJGZ7KWv9V/go-ipld-cbor"
2930
unixfs "gx/ipfs/QmUnHNqhSB1JgzVCxL1Kz3yb4bdyB4q1Z9AD5AUBVmt3fZ/go-unixfs"
3031
mocknet "gx/ipfs/QmVvV8JQmmqPCwXAaesWJPheUiEFQJ9HWRhWhuFuxVQxpR/go-libp2p/p2p/net/mock"
32+
apicid "gx/ipfs/QmWf8NwKFLbTBvAvZst3bYF7WEEetzxWyMhvQ885cj9MM8/go-cidutil/apicid"
3133
files "gx/ipfs/QmZMWMvWMVKCbHetJ4RgndbuEF1io2UpUxwQwtNjtYPzSC/go-ipfs-files"
3234
config "gx/ipfs/QmbK4EmM2Xx5fmbqK38TGP3PpY66r3tkXLZTcc7dF9mFwM/go-ipfs-config"
3335
mdag "gx/ipfs/QmcGt25mrjuB2kKW2zhPbXVZNHc4yoTDQ65NA8m6auP2f1/go-merkledag"

‎core/coreunix/add.go

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
ihelper "gx/ipfs/QmUnHNqhSB1JgzVCxL1Kz3yb4bdyB4q1Z9AD5AUBVmt3fZ/go-unixfs/importer/helpers"
2424
trickle "gx/ipfs/QmUnHNqhSB1JgzVCxL1Kz3yb4bdyB4q1Z9AD5AUBVmt3fZ/go-unixfs/importer/trickle"
2525
mfs "gx/ipfs/QmV8mXUh1M9qztax7vVdL1Apuz4c1eJZC5YactGxaJfWom/go-mfs"
26+
apicid "gx/ipfs/QmWf8NwKFLbTBvAvZst3bYF7WEEetzxWyMhvQ885cj9MM8/go-cidutil/apicid"
2627
files "gx/ipfs/QmZMWMvWMVKCbHetJ4RgndbuEF1io2UpUxwQwtNjtYPzSC/go-ipfs-files"
2728
dag "gx/ipfs/QmcGt25mrjuB2kKW2zhPbXVZNHc4yoTDQ65NA8m6auP2f1/go-merkledag"
2829
ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"

‎filestore/util.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
1010
blockstore "gx/ipfs/QmS2aqUZLJp8kF1ihE5rvDGE5LvmKDPnx32w9Z1BW9xLV5/go-ipfs-blockstore"
11+
apicid "gx/ipfs/QmWf8NwKFLbTBvAvZst3bYF7WEEetzxWyMhvQ885cj9MM8/go-cidutil/apicid"
1112
dshelp "gx/ipfs/QmauEMWPoSqggfpSDHMMXuDn12DTd7TaFBvn39eeurzKT2/go-ipfs-ds-help"
1213
ds "gx/ipfs/Qmf4xQhNomPNhrtZc67qSnfJSjxjXs9LWvknJtSXwimPrM/go-datastore"
1314
dsq "gx/ipfs/Qmf4xQhNomPNhrtZc67qSnfJSjxjXs9LWvknJtSXwimPrM/go-datastore/query"
@@ -60,7 +61,7 @@ func (s Status) Format() string {
6061
type ListRes struct {
6162
Status Status
6263
ErrorMsg string
63-
Key cid.Cid
64+
Key apicid.Cid
6465
FilePath string
6566
Offset uint64
6667
Size uint64
@@ -269,14 +270,14 @@ func mkListRes(c cid.Cid, d *pb.DataObj, err error) *ListRes {
269270
return &ListRes{
270271
Status: status,
271272
ErrorMsg: errorMsg,
272-
Key: c,
273+
Key: apicid.Cid{Cid: c},
273274
}
274275
}
275276

276277
return &ListRes{
277278
Status: status,
278279
ErrorMsg: errorMsg,
279-
Key: c,
280+
Key: apicid.Cid{Cid: c},
280281
FilePath: d.FilePath,
281282
Size: d.Size_,
282283
Offset: d.Offset,

‎test/sharness/t0045-ls.sh

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ test_description="Test ls command"
1111
test_init_ipfs
1212

1313
test_ls_cmd() {
14-
1514
test_expect_success "'ipfs add -r testData' succeeds" '
1615
mkdir -p testData testData/d1 testData/d2 &&
1716
echo "test" >testData/f1 &&
@@ -86,6 +85,15 @@ QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN 14 a
8685
EOF
8786
test_cmp expected_ls_headers actual_ls_headers
8887
'
88+
89+
test_expect_success "'ipfs ls --cid-base=base32 <three dir hashes>' succeeds" '
90+
ipfs ls --cid-base=base32 $(cid-fmt -v 1 -b base32 %s QmfNy183bXiRVyrhyWtq3TwHn79yHEkiAGFr18P7YNzESj QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss) >actual_ls_base32
91+
'
92+
93+
test_expect_success "'ipfs ls --cid-base=base32 <three dir hashes>' output looks good" '
94+
cid-fmt -b base32 -v 1 --filter %s < expected_ls > expected_ls_base32
95+
test_cmp expected_ls_base32 actual_ls_base32
96+
'
8997
}
9098

9199

‎test/sharness/t0085-pins.sh

+53-16
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ test_description="Test ipfs pinning operations"
1111

1212
test_pins() {
1313
EXTRA_ARGS=$1
14+
BASE=$2
15+
if [ -n "$BASE" ]; then
16+
BASE_ARGS="--cid-base=$BASE"
17+
fi
1418

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)
2327
'
2428

2529
test_expect_success "put all those hashes in a file" '
@@ -32,22 +36,53 @@ test_pins() {
3236
echo $HASH_G >> hashes
3337
'
3438

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+
3547
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
3754
'
3855

3956
test_expect_success "see if verify works" '
4057
ipfs pin verify
4158
'
4259

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
4681
'
4782

48-
test_expect_success "test pin ls hash" '
83+
test_expect_success "test pin ls $BASE_ARGS hash" '
4984
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 &&
5186
echo "$HASH_B recursive" > ls_hash_exp &&
5287
test_cmp ls_hash_exp ls_hash_out
5388
'
@@ -58,11 +93,11 @@ test_pins() {
5893

5994
test_expect_success "test pin update" '
6095
ipfs pin add "$HASH_A" &&
61-
ipfs pin ls > before_update &&
96+
ipfs pin ls $BASE_ARGS | tee before_update &&
6297
test_should_contain "$HASH_A" before_update &&
6398
test_must_fail grep -q "$HASH_B" before_update &&
6499
ipfs pin update --unpin=true "$HASH_A" "$HASH_B" &&
65-
ipfs pin ls > after_update &&
100+
ipfs pin ls $BASE_ARGS > after_update &&
66101
test_must_fail grep -q "$HASH_A" after_update &&
67102
test_should_contain "$HASH_B" after_update &&
68103
ipfs pin rm "$HASH_B"
@@ -129,6 +164,7 @@ test_init_ipfs
129164

130165
test_pins
131166
test_pins --progress
167+
test_pins '' base32
132168

133169
test_pins_error_reporting
134170
test_pins_error_reporting --progress
@@ -142,6 +178,7 @@ test_launch_ipfs_daemon --offline
142178

143179
test_pins
144180
test_pins --progress
181+
test_pins '' base32
145182

146183
test_pins_error_reporting
147184
test_pins_error_reporting --progress

‎test/sharness/t0095-refs.sh

+65-56
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,12 @@ test_expect_success "create and add folders for refs" '
7171
[[ "$root" == "$refsroot" ]]
7272
'
7373

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
7680
QmdytmR4wULMd3SLo6ePF4s3WcRHWcpnJZ7bHhoj3QB13v
7781
QmNkQvpiyAEtbeLviC7kqfifYoK1GXPcsSxTpP1yS3ykLa
7882
QmdytmR4wULMd3SLo6ePF4s3WcRHWcpnJZ7bHhoj3QB13v
@@ -87,54 +91,54 @@ QmSanP5DpxpqfDdS4yekHY1MqrVge47gtxQcp2e2yZ4UwS
8791
QmSFxnK675wQ9Kc1uqWKyJUaNxvSc2BP5DbXCD3x93oq61
8892
EOF
8993
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+
'
9397

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
97101
QmdytmR4wULMd3SLo6ePF4s3WcRHWcpnJZ7bHhoj3QB13v
98102
QmNkQvpiyAEtbeLviC7kqfifYoK1GXPcsSxTpP1yS3ykLa
99103
QmSanP5DpxpqfDdS4yekHY1MqrVge47gtxQcp2e2yZ4UwS
100104
QmSFxnK675wQ9Kc1uqWKyJUaNxvSc2BP5DbXCD3x93oq61
101105
QmXXazTjeNCKFnpW1D65vTKsTs8fbgkCWTv8Em4pdK2coH
102106
EOF
103107
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+
'
107111

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
111115
QmdytmR4wULMd3SLo6ePF4s3WcRHWcpnJZ7bHhoj3QB13v
112116
QmNkQvpiyAEtbeLviC7kqfifYoK1GXPcsSxTpP1yS3ykLa
113117
QmXXazTjeNCKFnpW1D65vTKsTs8fbgkCWTv8Em4pdK2coH
114118
QmSanP5DpxpqfDdS4yekHY1MqrVge47gtxQcp2e2yZ4UwS
115119
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+
'
119123

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
123127
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
138142
QmdytmR4wULMd3SLo6ePF4s3WcRHWcpnJZ7bHhoj3QB13v
139143
QmNkQvpiyAEtbeLviC7kqfifYoK1GXPcsSxTpP1yS3ykLa
140144
QmdytmR4wULMd3SLo6ePF4s3WcRHWcpnJZ7bHhoj3QB13v
@@ -144,33 +148,38 @@ QmNkQvpiyAEtbeLviC7kqfifYoK1GXPcsSxTpP1yS3ykLa
144148
QmSanP5DpxpqfDdS4yekHY1MqrVge47gtxQcp2e2yZ4UwS
145149
QmSFxnK675wQ9Kc1uqWKyJUaNxvSc2BP5DbXCD3x93oq61
146150
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
166170
QmdytmR4wULMd3SLo6ePF4s3WcRHWcpnJZ7bHhoj3QB13v
167171
QmNkQvpiyAEtbeLviC7kqfifYoK1GXPcsSxTpP1yS3ykLa
168172
QmSanP5DpxpqfDdS4yekHY1MqrVge47gtxQcp2e2yZ4UwS
169173
QmXXazTjeNCKFnpW1D65vTKsTs8fbgkCWTv8Em4pdK2coH
170174
QmSFxnK675wQ9Kc1uqWKyJUaNxvSc2BP5DbXCD3x93oq61
171175
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'
175184

176185
test_done

‎test/sharness/t0160-resolve.sh

+30-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ test_expect_success "resolve: prepare files" '
1212
a_hash=$(ipfs add -q -r a | tail -n1) &&
1313
b_hash=$(ipfs add -q -r a/b | tail -n1) &&
1414
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)
1518
'
1619

1720
test_expect_success "resolve: prepare dag" '
@@ -45,9 +48,10 @@ test_resolve_setup_name_fail() {
4548
test_resolve() {
4649
src=$1
4750
dst=$2
51+
extra=$3
4852

4953
test_expect_success "resolve succeeds: $src" '
50-
ipfs resolve -r "$src" >actual
54+
ipfs resolve $extra -r "$src" >actual
5155
'
5256

5357
test_expect_success "resolved correctly: $src -> $dst" '
@@ -57,7 +61,6 @@ test_resolve() {
5761
}
5862

5963
test_resolve_cmd() {
60-
6164
test_resolve "/ipfs/$a_hash" "/ipfs/$a_hash"
6265
test_resolve "/ipfs/$a_hash/b" "/ipfs/$b_hash"
6366
test_resolve "/ipfs/$a_hash/b/c" "/ipfs/$c_hash"
@@ -76,6 +79,30 @@ test_resolve_cmd() {
7679
test_resolve "/ipns/$id_hash" "/ipfs/$c_hash"
7780
}
7881

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+
79106
#todo remove this once the online resolve is fixed
80107
test_resolve_fail() {
81108
src=$1
@@ -117,6 +144,7 @@ test_resolve_cmd_fail() {
117144

118145
# should work offline
119146
test_resolve_cmd
147+
test_resolve_cmd_b32
120148

121149
# should work online
122150
test_launch_ipfs_daemon

‎test/sharness/t0271-filestore-utils.sh

+95-25
Original file line numberDiff line numberDiff line change
@@ -63,54 +63,56 @@ EOF
6363

6464
sort < verify_expect_file_order > verify_expect_key_order
6565

66+
IPFS_CMD="ipfs"
67+
6668
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)
6971
'
7072

7173
test_expect_success "nocopy add has right hash" '
7274
test "$HASH" = "$EXPHASH"
7375
'
7476

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 &&
7779
test_cmp ls_expect_key_order ls_actual
7880
'
7981

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 &&
8284
test_cmp ls_expect_file_order ls_actual
8385
'
8486

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 &&
8789
grep -q somedir/file1 ls_actual
8890
'
8991

9092
test_expect_success "can retrieve multi-block file" '
91-
ipfs cat $FILE3_HASH > file3.data &&
93+
$IPFS_CMD cat $FILE3_HASH > file3.data &&
9294
test_cmp somedir/file3 file3.data
9395
'
9496
}
9597

9698
# check that the filestore is in a clean state
9799
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
100102
test_cmp verify_expect_key_order verify_actual
101103
'
102104
}
103105

104106
test_filestore_verify() {
105107
test_filestore_state
106108

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
109111
test_cmp verify_expect_file_order verify_actual
110112
'
111113

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 &&
114116
grep -q somedir/file1 verify_actual
115117
'
116118

@@ -119,11 +121,11 @@ test_filestore_verify() {
119121
'
120122

121123
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
123125
'
124126

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 &&
127129
grep no-file verify_actual | grep -q somedir/file1
128130
'
129131

@@ -132,7 +134,7 @@ test_filestore_verify() {
132134
'
133135

134136
test_expect_success "block okay now" '
135-
ipfs cat $FILE1_HASH > file1.data &&
137+
$IPFS_CMD cat $FILE1_HASH > file1.data &&
136138
test_cmp somedir/file1 file1.data
137139
'
138140

@@ -141,11 +143,11 @@ test_filestore_verify() {
141143
'
142144

143145
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
145147
'
146148

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 &&
149151
grep changed verify_actual | grep -q somedir/file3
150152
'
151153

@@ -157,9 +159,9 @@ test_filestore_dups() {
157159
# make sure the filestore is in a clean state
158160
test_filestore_state
159161

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 &&
163165
echo "$FILE1_HASH" > dups_expect
164166
test_cmp dups_expect dups_actual
165167
'
@@ -195,4 +197,72 @@ test_filestore_dups
195197

196198
test_kill_ipfs_daemon
197199

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+
198268
test_done

‎test/sharness/t0272-urlstore.sh

+13
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ test_expect_success "add files using gateway address via url store" '
5151
ipfs pin add $HASH1 $HASH2
5252
'
5353

54+
test_expect_success "add files using gateway address via url store using --cid-base=base32" '
55+
HASH1b32=$(ipfs --cid-base=base32 urlstore add http://127.0.0.1:$GWAY_PORT/ipfs/$HASH1a) &&
56+
HASH2b32=$(ipfs --cid-base=base32 urlstore add http://127.0.0.1:$GWAY_PORT/ipfs/$HASH2a)
57+
'
58+
59+
5460
test_expect_success "make sure hashes are different" '
5561
test $HASH1a != $HASH1 &&
5662
test $HASH2a != $HASH2
@@ -154,4 +160,11 @@ test_expect_success "check that the hashes were correct" '
154160
test $HASH3e = $HASH3
155161
'
156162

163+
test_expect_success "check that the base32 hashes were correct" '
164+
HASH1e32=$(ipfs cid base32 $HASH1e)
165+
HASH2e32=$(ipfs cid base32 $HASH2e)
166+
test $HASH1e32 = $HASH1b32 &&
167+
test $HASH2e32 = $HASH2b32
168+
'
169+
157170
test_done

0 commit comments

Comments
 (0)
Please sign in to comment.