From f9fb8eadb557a3b43bf20da752da092208703a98 Mon Sep 17 00:00:00 2001 From: Iaroslav Gridin Date: Fri, 2 Mar 2018 21:57:56 +0200 Subject: [PATCH] ipfs add --pinpath --- core/commands/add.go | 8 ++++++++ core/coreunix/add.go | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/core/commands/add.go b/core/commands/add.go index 22171d9a597a..9d56af4a37c3 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -43,6 +43,7 @@ const ( fstoreCacheOptionName = "fscache" cidVersionOptionName = "cid-version" hashOptionName = "hash" + pinPathOptionName = "pinpath" ) const adderOutChanSize = 8 @@ -114,6 +115,7 @@ You can now check what blocks have been created by: cmdkit.BoolOption(hiddenOptionName, "H", "Include files that are hidden. Only takes effect on recursive add."), cmdkit.StringOption(chunkerOptionName, "s", "Chunking algorithm, size-[bytes] or rabin-[min]-[avg]-[max]").WithDefault("size-262144"), cmdkit.BoolOption(pinOptionName, "Pin this object when adding.").WithDefault(true), + cmdkit.StringOption(pinPathOptionName, "P", "Pin object under this path. Implies --pin=true").WithDefault(""), cmdkit.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes. (experimental)"), cmdkit.BoolOption(noCopyOptionName, "Add the file using filestore. Implies raw-leaves. (experimental)"), 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: fscache, _ := req.Options[fstoreCacheOptionName].(bool) cidVer, cidVerSet := req.Options[cidVersionOptionName].(int) hashFunStr, _ := req.Options[hashOptionName].(string) + pinPath, _ := req.Options[pinPathOptionName].(string) // The arguments are subject to the following constraints. // @@ -280,6 +283,11 @@ You can now check what blocks have been created by: fileAdder.RawLeaves = rawblks fileAdder.NoCopy = nocopy fileAdder.Prefix = &prefix + if pinPath == "" { + fileAdder.PinPath = "added/" + } else { + fileAdder.PinPath = pinPath + } if hash { md := dagtest.Mock() diff --git a/core/coreunix/add.go b/core/coreunix/add.go index f21367c7d050..c2354016d656 100644 --- a/core/coreunix/add.go +++ b/core/coreunix/add.go @@ -110,6 +110,7 @@ type Adder struct { tempRoot *cid.Cid Prefix *cid.Prefix liveNodes uint64 + PinPath string } func (adder *Adder) mfsRoot() (*mfs.Root, error) { @@ -202,14 +203,14 @@ func (adder *Adder) PinRoot() error { } if adder.tempRoot != nil { - err := adder.pinning.UnpinCidUnderPrefix("added/", adder.tempRoot, true) + err := adder.pinning.UnpinCidUnderPrefix(adder.PinPath, adder.tempRoot, true) if err != nil { return err } adder.tempRoot = rnk } - return adder.pinning.AddPin("added/", rnk, true) + return adder.pinning.AddPin(adder.PinPath, rnk, true) } // Finalize flushes the mfs root directory and returns the mfs root node.