changed pinning to be recursive by default

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

License: MIT
Signed-off-by: ForrestWeston <Forrest.Weston@gmail.com>
This commit is contained in:
ForrestWeston 2015-10-09 17:35:23 -07:00
parent 107409cee8
commit 01239147b7
3 changed files with 39 additions and 30 deletions

View File

@ -57,7 +57,7 @@ on disk.
return
}
if !found {
recursive = false
recursive = true
}
added, err := corerepo.Pin(n, req.Context(), req.Arguments(), recursive)
@ -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"
@ -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.
`,
},
@ -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)
@ -153,26 +153,27 @@ 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.
Returns a list of objects that are pinned locally.
By default, only recursively pinned returned, but others may be shown via the '--type' flag.
`,
LongDescription: `
Returns a list of hashes of objects being pinned. Objects that are indirectly
or recursively pinned are not included in the list.
Use --type=<type> to specify the type of pinned keys to list. Valid values are:
* "direct": pin that specific object.
* "recursive": pin that specific object, and indirectly pin all its decendants
* "indirect": pinned indirectly by an ancestor (like a refcount)
* "all"
To see the ref count on indirect pins, pass the -count option flag.
Defaults to "direct".
Returns a list of objects that are pinned locally.
By default, only recursively pinned returned, but others may be shown via the '--type' flag.
Example:
$ echo "hello" | ipfs add -q
QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN
$ ipfs pin ls
QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN
# now remove the pin, and repin it directly
$ ipfs pin rm QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN
$ ipfs pin add -r=false QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN
$ ipfs pin ls --type=direct
QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN
`,
},
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"),
},
@ -189,7 +190,7 @@ Defaults to "direct".
return
}
if !found {
typeStr = "direct"
typeStr = "recursive"
}
switch typeStr {

View File

@ -74,20 +74,28 @@ test_expect_success "file no longer pinned" '
test_sort_cmp expected2 actual2
'
test_expect_success "recursively pin afile" '
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)" '
ipfs pin rm "$HASH"
'
test_expect_success "recursively pin 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
'
@ -95,7 +103,7 @@ 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" '
@ -142,7 +150,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
'

View File

@ -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 &&