Skip to content

Commit 8366884

Browse files
iaroslav-gridinVoker57
authored andcommitted
Named pins, storing pins in Datastore
* Change pin structure to a tree stored in KV store * Adjust pin-related commands accordingly * Make pinning routines use meaningful default prefixes License: MIT Signed-off-by: Iaroslav Gridin <voker57@gmail.com> # Conflicts: # assets/assets.go # core/builder.go # core/commands/add.go # core/commands/dag/dag.go # core/commands/object/object.go # core/commands/pin.go # core/commands/urlstore.go # core/coreapi/interface/options/object.go # core/coreapi/interface/options/pin.go # core/coreapi/interface/options/unixfs.go # core/coreapi/interface/pin.go # core/coreapi/interface/tests/pin.go # core/coreapi/interface/tests/unixfs.go # core/coreapi/pin.go # core/corerepo/pinning.go # core/coreunix/add.go # exchange/reprovide/providers.go # pin/pin.go # pin/pin_test.go # pin/set.go # pin/set_test.go # test/sharness/t0080-repo.sh # test/sharness/t0085-pins.sh # test/sharness/t0252-files-gc.sh # test/sharness/t0272-urlstore.sh
1 parent 07bf2bd commit 8366884

39 files changed

+640
-1221
lines changed

assets/assets.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ func addAssetList(nd *core.IpfsNode, l []string) (cid.Cid, error) {
7878
}
7979
}
8080

81-
if err := api.Pin().Add(nd.Context(), basePath); err != nil {
81+
if err := api.Pin().Add(nd.Context(), "assets", basePath); err != nil {
8282
return cid.Cid{}, err
8383
}
8484

8585
return basePath.Cid(), nil
86+
8687
}

core/commands/add.go

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const (
3838
onlyHashOptionName = "only-hash"
3939
chunkerOptionName = "chunker"
4040
pinOptionName = "pin"
41+
pinPathOptionName = "pinpath"
4142
rawLeavesOptionName = "raw-leaves"
4243
noCopyOptionName = "nocopy"
4344
fstoreCacheOptionName = "fscache"
@@ -123,6 +124,7 @@ You can now check what blocks have been created by:
123124
cmds.StringOption(chunkerOptionName, "s", "Chunking algorithm, size-[bytes] or rabin-[min]-[avg]-[max]").WithDefault("size-262144"),
124125
cmds.BoolOption(pinOptionName, "Pin this object when adding.").WithDefault(true),
125126
cmds.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes. (experimental)"),
127+
cmds.StringOption(pinPathOptionName, "P", "Pin object under this path.").WithDefault("added/"),
126128
cmds.BoolOption(noCopyOptionName, "Add the file using filestore. Implies raw-leaves. (experimental)"),
127129
cmds.BoolOption(fstoreCacheOptionName, "Check the filestore for pre-existing blocks. (experimental)"),
128130
cmds.IntOption(cidVersionOptionName, "CID version. Defaults to 0 unless an option that depends on CIDv1 is passed. (experimental)"),
@@ -162,6 +164,7 @@ You can now check what blocks have been created by:
162164
silent, _ := req.Options[silentOptionName].(bool)
163165
chunker, _ := req.Options[chunkerOptionName].(string)
164166
dopin, _ := req.Options[pinOptionName].(bool)
167+
pinPath, _ := req.Options[pinPathOptionName].(string)
165168
rawblks, rbset := req.Options[rawLeavesOptionName].(bool)
166169
nocopy, _ := req.Options[noCopyOptionName].(bool)
167170
fscache, _ := req.Options[fstoreCacheOptionName].(bool)
@@ -196,6 +199,7 @@ You can now check what blocks have been created by:
196199
options.Unixfs.Chunker(chunker),
197200

198201
options.Unixfs.Pin(dopin),
202+
options.Unixfs.PinPath(pinPath),
199203
options.Unixfs.HashOnly(hash),
200204
options.Unixfs.FsCache(fscache),
201205
options.Unixfs.Nocopy(nocopy),

core/commands/dag/dag.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ into an object of the specified format.
6161
Options: []cmds.Option{
6262
cmds.StringOption("format", "f", "Format that the object will be added as.").WithDefault("cbor"),
6363
cmds.StringOption("input-enc", "Format that the input object will be.").WithDefault("json"),
64-
cmds.BoolOption("pin", "Pin this object when adding."),
64+
cmds.StringOption("pin", "Pin this object when adding.").WithDefault(""),
6565
cmds.StringOption("hash", "Hash function to use").WithDefault(""),
6666
},
6767
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
@@ -73,7 +73,7 @@ into an object of the specified format.
7373
ienc, _ := req.Options["input-enc"].(string)
7474
format, _ := req.Options["format"].(string)
7575
hash, _ := req.Options["hash"].(string)
76-
dopin, _ := req.Options["pin"].(bool)
76+
pinpath, _ := req.Options["pin"].(string)
7777

7878
// mhType tells inputParser which hash should be used. MaxUint64 means 'use
7979
// default hash' (sha256 for cbor, sha1 for git..)
@@ -88,9 +88,6 @@ into an object of the specified format.
8888
}
8989

9090
var adder ipld.NodeAdder = api.Dag()
91-
if dopin {
92-
adder = api.Dag().Pinning()
93-
}
9491
b := ipld.NewBatch(req.Context, adder)
9592

9693
it := req.Files.Entries()
@@ -107,10 +104,13 @@ into an object of the specified format.
107104
return fmt.Errorf("no node returned from ParseInputs")
108105
}
109106

110-
for _, nd := range nds {
111-
err := b.Add(req.Context, nd)
112-
if err != nil {
113-
return err
107+
if pinpath != "" {
108+
109+
for _, nd := range nds {
110+
err := api.Pin().Add(req.Context, pinpath, path.IpfsPath(nd.Cid()))
111+
if err != nil {
112+
return err
113+
}
114114
}
115115
}
116116

core/commands/object/object.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ And then run:
404404
cmds.StringOption(datafieldencOptionName, "Encoding type of the data field, either \"text\" or \"base64\".").WithDefault("text"),
405405
cmds.BoolOption(pinOptionName, "Pin this object when adding."),
406406
cmds.BoolOption(quietOptionName, "q", "Write minimal output."),
407+
cmds.StringOption("pinpath", "Pin under this path").WithDefault("added/"),
407408
},
408409
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
409410
api, err := cmdenv.GetApi(env, req)
@@ -431,15 +432,21 @@ And then run:
431432
return err
432433
}
433434

434-
dopin, _ := req.Options[pinOptionName].(bool)
435+
pinpath, _ := req.Options["pinpath"].(string)
436+
if err != nil {
437+
return err
438+
}
439+
440+
pin, _ := req.Options["pin"].(bool)
435441
if err != nil {
436442
return err
437443
}
438444

439445
p, err := api.Object().Put(req.Context, file,
440446
options.Object.DataType(datafieldenc),
441447
options.Object.InputEnc(inputenc),
442-
options.Object.Pin(dopin))
448+
options.Object.Pin(pin),
449+
options.Object.PinPath(pinpath))
443450
if err != nil {
444451
return err
445452
}

0 commit comments

Comments
 (0)