Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a --no-pin option to ipfs add #1931

Merged
merged 1 commit into from
Nov 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
hiddenOptionName = "hidden"
onlyHashOptionName = "only-hash"
chunkerOptionName = "chunker"
pinOptionName = "pin"
)

var AddCmd = &cmds.Command{
Expand All @@ -49,6 +50,7 @@ remains to be implemented.
cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object"),
cmds.BoolOption(hiddenOptionName, "H", "Include files that are hidden"),
cmds.StringOption(chunkerOptionName, "s", "chunking algorithm to use"),
cmds.BoolOption(pinOptionName, "Pin this object when adding. Default true"),
},
PreRun: func(req cmds.Request) error {
if quiet, _, _ := req.Option(quietOptionName).Bool(); quiet {
Expand Down Expand Up @@ -94,6 +96,11 @@ remains to be implemented.
hash, _, _ := req.Option(onlyHashOptionName).Bool()
hidden, _, _ := req.Option(hiddenOptionName).Bool()
chunker, _, _ := req.Option(chunkerOptionName).String()
dopin, pin_found, _ := req.Option(pinOptionName).Bool()

if !pin_found { // default
dopin = true
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to set the default on the commands lib itself? (am not sure.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is the js trick !!dopin, don't know if it works in golang.


if hash {
nilnode, err := core.NewNode(n.Context(), &core.BuildCfg{
Expand All @@ -117,6 +124,7 @@ remains to be implemented.
fileAdder.Hidden = hidden
fileAdder.Trickle = trickle
fileAdder.Wrap = wrap
fileAdder.Pin = dopin

// addAllFiles loops over a convenience slice file to
// add each file individually. e.g. 'ipfs add a b c'
Expand Down
3 changes: 3 additions & 0 deletions core/coreunix/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
31 changes: 31 additions & 0 deletions test/sharness/t0081-repo-pinning.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -248,6 +251,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 --pin=false 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 --pin=false 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