Skip to content

Commit

Permalink
changed pinning to be recursive by default
Browse files Browse the repository at this point in the history
pin add, pin rm, and pin ls will be recursive unless
specified with '=false' eg. 'ipfs pin add -r=false <file>'
tests for pinning have been updated/added
  • Loading branch information
frrist committed Oct 10, 2015
1 parent b70ca8e commit 174da4a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
22 changes: 10 additions & 12 deletions core/commands/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ on disk.
return
}
if !found {
recursive = false
recursive = true
}

added, err := corerepo.Pin(n, req.Context(), req.Arguments(), recursive)
Expand All @@ -76,8 +76,8 @@ on disk.
}

var pintype string
rec, _, _ := res.Request().Option("recursive").Bool()
if rec {
rec, found, _ := res.Request().Option("recursive").Bool()
if rec || !found {
pintype = "recursively"
} else {
pintype = "directly"
Expand All @@ -94,9 +94,9 @@ on disk.

var rmPinCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Unpin an object from local storage",
Tagline: "Recursively unpin an object from local storage",
ShortDescription: `
Removes the pin from the given object allowing it to be garbage
Recursively removes the pin from the given object allowing it to be garbage
collected if needed.
`,
},
Expand All @@ -122,7 +122,7 @@ collected if needed.
return
}
if !found {
recursive = false // default
recursive = true // default
}

removed, err := corerepo.Unpin(n, req.Context(), req.Arguments(), recursive)
Expand Down Expand Up @@ -153,12 +153,10 @@ var listPinCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "List objects pinned to local storage",
ShortDescription: `
Returns a list of hashes of objects being pinned. Objects that are indirectly
or recursively pinned are not included in the list.
Recursively returns a list of hashes of objects being pinned.
`,
LongDescription: `
Returns a list of hashes of objects being pinned. Objects that are indirectly
or recursively pinned are not included in the list.
Recursively returns a list of hashes of objects being pinned.
Use --type=<type> to specify the type of pinned keys to list. Valid values are:
* "direct": pin that specific object.
Expand All @@ -172,7 +170,7 @@ Defaults to "direct".
},

Options: []cmds.Option{
cmds.StringOption("type", "t", "The type of pinned keys to list. Can be \"direct\", \"indirect\", \"recursive\", or \"all\". Defaults to \"direct\""),
cmds.StringOption("type", "t", "The type of pinned keys to list. Can be \"direct\", \"indirect\", \"recursive\", or \"all\". Defaults to \"recursive\""),
cmds.BoolOption("count", "n", "Show refcount when listing indirect pins"),
cmds.BoolOption("quiet", "q", "Write just hashes of objects"),
},
Expand All @@ -189,7 +187,7 @@ Defaults to "direct".
return
}
if !found {
typeStr = "direct"
typeStr = "recursive"
}

switch typeStr {
Expand Down
20 changes: 15 additions & 5 deletions test/sharness/t0080-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,38 @@ test_expect_success "file no longer pinned" '
test_sort_cmp expected2 actual2
'

test_expect_success "recursively pin afile(default action)" '
HASH=`ipfs add -q afile` &&
ipfs pin add "$HASH"
'

test_expect_success "recursively pin rm afile (default action)" '
HASH=`ipfs add -q afile` &&
ipfs pin rm "$HASH"
'

test_expect_success "recursively pin afile" '
HASH=`ipfs add -q afile` &&
ipfs pin add -r "$HASH"
'

test_expect_success "pinning directly should fail now" '
echo "Error: pin: $HASH already pinned recursively" >expected3 &&
test_must_fail ipfs pin add "$HASH" 2>actual3 &&
test_must_fail ipfs pin add -r=false "$HASH" 2>actual3 &&
test_cmp expected3 actual3
'

test_expect_success "'ipfs pin rm <hash>' should fail" '
test_expect_success "'ipfs pin rm -r=false <hash>' should fail" '
echo "Error: $HASH is pinned recursively" >expected4 &&
test_must_fail ipfs pin rm "$HASH" 2>actual4 &&
test_must_fail ipfs pin rm -r=false "$HASH" 2>actual4 &&
test_cmp expected4 actual4
'

test_expect_success "remove recursive pin, add direct" '
echo "unpinned $HASH" >expected5 &&
ipfs pin rm -r "$HASH" >actual5 &&
test_cmp expected5 actual5 &&
ipfs pin add "$HASH"
ipfs pin add -r=false "$HASH"
'

test_expect_success "remove direct pin" '
Expand Down Expand Up @@ -142,7 +152,7 @@ test_expect_success "pin something directly" '
test_cmp expected9 actual9 &&
echo "pinned $DIRECTPIN directly" >expected10 &&
ipfs pin add "$DIRECTPIN" >actual10 &&
ipfs pin add -r=false "$DIRECTPIN" >actual10 &&
test_cmp expected10 actual10
'

Expand Down
6 changes: 3 additions & 3 deletions test/sharness/t0081-repo-pinning.sh
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ test_expect_success "none are pinned any more" '
'

test_expect_success "pin some directly and indirectly" '
ipfs pin add "$HASH_DIR1" >actual7 &&
ipfs pin add -r "$HASH_DIR2" >>actual7 &&
ipfs pin add "$HASH_FILE1" >>actual7 &&
ipfs pin add -r=false "$HASH_DIR1" >actual7 &&
ipfs pin add -r=true "$HASH_DIR2" >>actual7 &&
ipfs pin add -r=false "$HASH_FILE1" >>actual7 &&
echo "pinned $HASH_DIR1 directly" >expected7 &&
echo "pinned $HASH_DIR2 recursively" >>expected7 &&
echo "pinned $HASH_FILE1 directly" >>expected7 &&
Expand Down

0 comments on commit 174da4a

Please # to comment.