Skip to content

Commit f9fb8ea

Browse files
committed
ipfs add --pinpath
1 parent 4761db1 commit f9fb8ea

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

core/commands/add.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const (
4343
fstoreCacheOptionName = "fscache"
4444
cidVersionOptionName = "cid-version"
4545
hashOptionName = "hash"
46+
pinPathOptionName = "pinpath"
4647
)
4748

4849
const adderOutChanSize = 8
@@ -114,6 +115,7 @@ You can now check what blocks have been created by:
114115
cmdkit.BoolOption(hiddenOptionName, "H", "Include files that are hidden. Only takes effect on recursive add."),
115116
cmdkit.StringOption(chunkerOptionName, "s", "Chunking algorithm, size-[bytes] or rabin-[min]-[avg]-[max]").WithDefault("size-262144"),
116117
cmdkit.BoolOption(pinOptionName, "Pin this object when adding.").WithDefault(true),
118+
cmdkit.StringOption(pinPathOptionName, "P", "Pin object under this path. Implies --pin=true").WithDefault(""),
117119
cmdkit.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes. (experimental)"),
118120
cmdkit.BoolOption(noCopyOptionName, "Add the file using filestore. Implies raw-leaves. (experimental)"),
119121
cmdkit.BoolOption(fstoreCacheOptionName, "Check the filestore for pre-existing blocks. (experimental)"),
@@ -172,6 +174,7 @@ You can now check what blocks have been created by:
172174
fscache, _ := req.Options[fstoreCacheOptionName].(bool)
173175
cidVer, cidVerSet := req.Options[cidVersionOptionName].(int)
174176
hashFunStr, _ := req.Options[hashOptionName].(string)
177+
pinPath, _ := req.Options[pinPathOptionName].(string)
175178

176179
// The arguments are subject to the following constraints.
177180
//
@@ -280,6 +283,11 @@ You can now check what blocks have been created by:
280283
fileAdder.RawLeaves = rawblks
281284
fileAdder.NoCopy = nocopy
282285
fileAdder.Prefix = &prefix
286+
if pinPath == "" {
287+
fileAdder.PinPath = "added/"
288+
} else {
289+
fileAdder.PinPath = pinPath
290+
}
283291

284292
if hash {
285293
md := dagtest.Mock()

core/coreunix/add.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ type Adder struct {
110110
tempRoot *cid.Cid
111111
Prefix *cid.Prefix
112112
liveNodes uint64
113+
PinPath string
113114
}
114115

115116
func (adder *Adder) mfsRoot() (*mfs.Root, error) {
@@ -202,14 +203,14 @@ func (adder *Adder) PinRoot() error {
202203
}
203204

204205
if adder.tempRoot != nil {
205-
err := adder.pinning.UnpinCidUnderPrefix("added/", adder.tempRoot, true)
206+
err := adder.pinning.UnpinCidUnderPrefix(adder.PinPath, adder.tempRoot, true)
206207
if err != nil {
207208
return err
208209
}
209210
adder.tempRoot = rnk
210211
}
211212

212-
return adder.pinning.AddPin("added/", rnk, true)
213+
return adder.pinning.AddPin(adder.PinPath, rnk, true)
213214
}
214215

215216
// Finalize flushes the mfs root directory and returns the mfs root node.

0 commit comments

Comments
 (0)