diff --git a/core/commands/add.go b/core/commands/add.go index 8a3505647485..cda7b7be0eea 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -24,6 +24,7 @@ const ( hiddenOptionName = "hidden" onlyHashOptionName = "only-hash" chunkerOptionName = "chunker" + noPinOptionName = "no-pin" ) var AddCmd = &cmds.Command{ @@ -49,6 +50,7 @@ remains to be implemented. cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object"), cmds.BoolOption(hiddenOptionName, "Include files that are hidden"), cmds.StringOption(chunkerOptionName, "s", "chunking algorithm to use"), + cmds.BoolOption(noPinOptionName, "Do not pin this object when adding"), }, PreRun: func(req cmds.Request) error { if quiet, _, _ := req.Option(quietOptionName).Bool(); quiet { @@ -86,6 +88,7 @@ remains to be implemented. hash, _, _ := req.Option(onlyHashOptionName).Bool() hidden, _, _ := req.Option(hiddenOptionName).Bool() chunker, _, _ := req.Option(chunkerOptionName).String() + nopin, _, _ := req.Option(noPinOptionName).Bool() if hash { nilnode, err := core.NewNode(n.Context(), &core.BuildCfg{ @@ -109,6 +112,7 @@ remains to be implemented. fileAdder.Hidden = hidden fileAdder.Trickle = trickle fileAdder.Wrap = wrap + fileAdder.Pin = !nopin // addAllFiles loops over a convenience slice file to // add each file individually. e.g. 'ipfs add a b c' diff --git a/core/coreunix/add.go b/core/coreunix/add.go index 27f9ed620a6f..df690bdf87fe 100644 --- a/core/coreunix/add.go +++ b/core/coreunix/add.go @@ -140,6 +140,9 @@ func (params *Adder) PinRoot() error { if err != nil { return err } + if !params.Pin { + return nil + } rnk, err := root.Key() if err != nil { diff --git a/test/sharness/t0081-repo-pinning.sh b/test/sharness/t0081-repo-pinning.sh index 92ed7a55e584..72178825d19b 100755 --- a/test/sharness/t0081-repo-pinning.sh +++ b/test/sharness/t0081-repo-pinning.sh @@ -71,6 +71,9 @@ HASH_DIR4="QmW98gV71Ns4bX7QbgWAqLiGF3SDC1JpveZSgBh4ExaSAd" HASH_DIR3="QmRsCaNBMkweZ9vHT5PJRd2TT9rtNKEKyuognCEVxZxF1H" HASH_DIR2="QmTUTQAgeVfughDSFukMZLbfGvetDJY7Ef5cDXkKK4abKC" HASH_DIR1="QmNyZVFbgvmzguS2jVMRb8PQMNcCMJrn9E3doDhBbcPNTY" +HASH_NOPINDIR="QmWHjrRJYSfYKz5V9dWWSKu47GdY7NewyRhyTiroXgWcDU" +HASH_NOPIN_FILE1="QmUJT3GQi1dxQyTZbkaWeer9GkCn1d3W3HHRLSDr6PTcpx" +HASH_NOPIN_FILE2="QmarR7m9JT7qHEGhuFNZUEMAnoZ8E9QAfsthHCQ9Y2GfoT" DIR1="dir1" DIR2="dir1/dir2" @@ -247,6 +250,34 @@ test_expect_success "recursive pin fails without objects" ' test_fsh cat err_expected8 ' +test_expect_success "test add nopin file" ' + echo "test nopin data" > test_nopin_data && + NOPINHASH=$(ipfs add -q --no-pin test_nopin_data) && + test_pin_flag "$NOPINHASH" direct false && + test_pin_flag "$NOPINHASH" indirect false && + test_pin_flag "$NOPINHASH" recursive false +' + + +test_expect_success "test add nopin dir" ' + mkdir nopin_dir1 && + echo "some nopin text 1" >nopin_dir1/file1 && + echo "some nopin text 2" >nopin_dir1/file2 && + ipfs add -q -r --no-pin nopin_dir1 | tail -n1 >actual1 && + echo "$HASH_NOPINDIR" >expected1 && + test_cmp actual1 expected1 && + test_pin_flag "$HASH_NOPINDIR" direct false && + test_pin_flag "$HASH_NOPINDIR" indirect false && + test_pin_flag "$HASH_NOPINDIR" recursive false && + test_pin_flag "$HASH_NOPIN_FILE1" direct false && + test_pin_flag "$HASH_NOPIN_FILE1" indirect false && + test_pin_flag "$HASH_NOPIN_FILE1" recursive false && + test_pin_flag "$HASH_NOPIN_FILE2" direct false && + test_pin_flag "$HASH_NOPIN_FILE2" indirect false && + test_pin_flag "$HASH_NOPIN_FILE2" recursive false + +' + # test_kill_ipfs_daemon test_done