@cryptotaxi247 / kubo / commits / b6f28dad1

Add a --pin option to `ipfs add` (allowing --pin=false)

Implements a solution for #1908 This PR replaces #1909 License: MIT Signed-off-by: Andrew Chin <achin@eminence32.net>

Andrew Chin committed Nov 2, 2015 at 13:38 UTC b6f28dad1b59f87d0f96e3923c79c35c0e7da370
3 files changed +42
core/commands/add.go
+8
@@ -24,6 +24,7 @@ const (
24 hiddenOptionName = "hidden"
25 onlyHashOptionName = "only-hash"
26 chunkerOptionName = "chunker"
27 + pinOptionName = "pin"
28 )
29
30 var AddCmd = &cmds.Command{
@@ -49,6 +50,7 @@ remains to be implemented.
50 cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object"),
51 cmds.BoolOption(hiddenOptionName, "H", "Include files that are hidden"),
52 cmds.StringOption(chunkerOptionName, "s", "chunking algorithm to use"),
53 + cmds.BoolOption(pinOptionName, "Pin this object when adding. Default true"),
54 },
55 PreRun: func(req cmds.Request) error {
56 if quiet, _, _ := req.Option(quietOptionName).Bool(); quiet {
@@ -94,6 +96,11 @@ remains to be implemented.
96 hash, _, _ := req.Option(onlyHashOptionName).Bool()
97 hidden, _, _ := req.Option(hiddenOptionName).Bool()
98 chunker, _, _ := req.Option(chunkerOptionName).String()
99 + dopin, pin_found, _ := req.Option(pinOptionName).Bool()
100 +
101 + if !pin_found { // default
102 + dopin = true
103 + }
104
105 if hash {
106 nilnode, err := core.NewNode(n.Context(), &core.BuildCfg{
@@ -117,6 +124,7 @@ remains to be implemented.
124 fileAdder.Hidden = hidden
125 fileAdder.Trickle = trickle
126 fileAdder.Wrap = wrap
127 + fileAdder.Pin = dopin
128
129 // addAllFiles loops over a convenience slice file to
130 // add each file individually. e.g. 'ipfs add a b c'
core/coreunix/add.go
+3
@@ -140,6 +140,9 @@ func (params *Adder) PinRoot() error {
140 if err != nil {
141 return err
142 }
143 + if !params.Pin {
144 + return nil
145 + }
146
147 rnk, err := root.Key()
148 if err != nil {
test/sharness/t0081-repo-pinning.sh
+31
@@ -71,6 +71,9 @@ HASH_DIR4="QmW98gV71Ns4bX7QbgWAqLiGF3SDC1JpveZSgBh4ExaSAd"
71 HASH_DIR3="QmRsCaNBMkweZ9vHT5PJRd2TT9rtNKEKyuognCEVxZxF1H"
72 HASH_DIR2="QmTUTQAgeVfughDSFukMZLbfGvetDJY7Ef5cDXkKK4abKC"
73 HASH_DIR1="QmNyZVFbgvmzguS2jVMRb8PQMNcCMJrn9E3doDhBbcPNTY"
74 +HASH_NOPINDIR="QmWHjrRJYSfYKz5V9dWWSKu47GdY7NewyRhyTiroXgWcDU"
75 +HASH_NOPIN_FILE1="QmUJT3GQi1dxQyTZbkaWeer9GkCn1d3W3HHRLSDr6PTcpx"
76 +HASH_NOPIN_FILE2="QmarR7m9JT7qHEGhuFNZUEMAnoZ8E9QAfsthHCQ9Y2GfoT"
77
78 DIR1="dir1"
79 DIR2="dir1/dir2"
@@ -248,6 +251,34 @@ test_expect_success "recursive pin fails without objects" '
251 test_fsh cat err_expected8
252 '
253
254 +test_expect_success "test add nopin file" '
255 + echo "test nopin data" > test_nopin_data &&
256 + NOPINHASH=$(ipfs add -q --pin=false test_nopin_data) &&
257 + test_pin_flag "$NOPINHASH" direct false &&
258 + test_pin_flag "$NOPINHASH" indirect false &&
259 + test_pin_flag "$NOPINHASH" recursive false
260 +'
261 +
262 +
263 +test_expect_success "test add nopin dir" '
264 + mkdir nopin_dir1 &&
265 + echo "some nopin text 1" >nopin_dir1/file1 &&
266 + echo "some nopin text 2" >nopin_dir1/file2 &&
267 + ipfs add -q -r --pin=false nopin_dir1 | tail -n1 >actual1 &&
268 + echo "$HASH_NOPINDIR" >expected1 &&
269 + test_cmp actual1 expected1 &&
270 + test_pin_flag "$HASH_NOPINDIR" direct false &&
271 + test_pin_flag "$HASH_NOPINDIR" indirect false &&
272 + test_pin_flag "$HASH_NOPINDIR" recursive false &&
273 + test_pin_flag "$HASH_NOPIN_FILE1" direct false &&
274 + test_pin_flag "$HASH_NOPIN_FILE1" indirect false &&
275 + test_pin_flag "$HASH_NOPIN_FILE1" recursive false &&
276 + test_pin_flag "$HASH_NOPIN_FILE2" direct false &&
277 + test_pin_flag "$HASH_NOPIN_FILE2" indirect false &&
278 + test_pin_flag "$HASH_NOPIN_FILE2" recursive false
279 +
280 +'
281 +
282 # test_kill_ipfs_daemon
283
284 test_done