@cryptotaxi247 / kubo / commits / 01239147b

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>

ForrestWeston committed Oct 9, 2015 at 17:35 UTC 01239147b7bf8cae69b0a33b58c70b5b596ad3da
3 files changed +39 -30
core/commands/pin.go
+22 -21
@@ -57,7 +57,7 @@ on disk.
57 return
58 }
59 if !found {
60 - recursive = false
60 + recursive = true
61 }
62
63 added, err := corerepo.Pin(n, req.Context(), req.Arguments(), recursive)
@@ -76,8 +76,8 @@ on disk.
76 }
77
78 var pintype string
79 - rec, _, _ := res.Request().Option("recursive").Bool()
80 - if rec {
79 + rec, found, _ := res.Request().Option("recursive").Bool()
80 + if rec || !found {
81 pintype = "recursively"
82 } else {
83 pintype = "directly"
@@ -94,9 +94,9 @@ on disk.
94
95 var rmPinCmd = &cmds.Command{
96 Helptext: cmds.HelpText{
97 - Tagline: "Unpin an object from local storage",
97 + Tagline: "Recursively unpin an object from local storage",
98 ShortDescription: `
99 -Removes the pin from the given object allowing it to be garbage
99 +Recursively removes the pin from the given object allowing it to be garbage
100 collected if needed.
101 `,
102 },
@@ -122,7 +122,7 @@ collected if needed.
122 return
123 }
124 if !found {
125 - recursive = false // default
125 + recursive = true // default
126 }
127
128 removed, err := corerepo.Unpin(n, req.Context(), req.Arguments(), recursive)
@@ -153,26 +153,27 @@ var listPinCmd = &cmds.Command{
153 Helptext: cmds.HelpText{
154 Tagline: "List objects pinned to local storage",
155 ShortDescription: `
156 -Returns a list of hashes of objects being pinned. Objects that are indirectly
157 -or recursively pinned are not included in the list.
156 +Returns a list of objects that are pinned locally.
157 +By default, only recursively pinned returned, but others may be shown via the '--type' flag.
158 `,
159 LongDescription: `
160 -Returns a list of hashes of objects being pinned. Objects that are indirectly
161 -or recursively pinned are not included in the list.
162 -
163 -Use --type=<type> to specify the type of pinned keys to list. Valid values are:
164 - * "direct": pin that specific object.
165 - * "recursive": pin that specific object, and indirectly pin all its decendants
166 - * "indirect": pinned indirectly by an ancestor (like a refcount)
167 - * "all"
168 -
169 -To see the ref count on indirect pins, pass the -count option flag.
170 -Defaults to "direct".
160 +Returns a list of objects that are pinned locally.
161 +By default, only recursively pinned returned, but others may be shown via the '--type' flag.
162 +Example:
163 + $ echo "hello" | ipfs add -q
164 + QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN
165 + $ ipfs pin ls
166 + QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN
167 + # now remove the pin, and repin it directly
168 + $ ipfs pin rm QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN
169 + $ ipfs pin add -r=false QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN
170 + $ ipfs pin ls --type=direct
171 + QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN
172 `,
173 },
174
175 Options: []cmds.Option{
175 - cmds.StringOption("type", "t", "The type of pinned keys to list. Can be \"direct\", \"indirect\", \"recursive\", or \"all\". Defaults to \"direct\""),
176 + cmds.StringOption("type", "t", "The type of pinned keys to list. Can be \"direct\", \"indirect\", \"recursive\", or \"all\". Defaults to \"recursive\""),
177 cmds.BoolOption("count", "n", "Show refcount when listing indirect pins"),
178 cmds.BoolOption("quiet", "q", "Write just hashes of objects"),
179 },
@@ -189,7 +190,7 @@ Defaults to "direct".
190 return
191 }
192 if !found {
192 - typeStr = "direct"
193 + typeStr = "recursive"
194 }
195
196 switch typeStr {
test/sharness/t0080-repo.sh
+14 -6
@@ -74,20 +74,28 @@ test_expect_success "file no longer pinned" '
74 test_sort_cmp expected2 actual2
75 '
76
77 -test_expect_success "recursively pin afile" '
77 +test_expect_success "recursively pin afile(default action)" '
78 HASH=`ipfs add -q afile` &&
79 + ipfs pin add "$HASH"
80 +'
81 +
82 +test_expect_success "recursively pin rm afile (default action)" '
83 + ipfs pin rm "$HASH"
84 +'
85 +
86 +test_expect_success "recursively pin afile" '
87 ipfs pin add -r "$HASH"
88 '
89
90 test_expect_success "pinning directly should fail now" '
91 echo "Error: pin: $HASH already pinned recursively" >expected3 &&
84 - test_must_fail ipfs pin add "$HASH" 2>actual3 &&
92 + test_must_fail ipfs pin add -r=false "$HASH" 2>actual3 &&
93 test_cmp expected3 actual3
94 '
95
88 -test_expect_success "'ipfs pin rm <hash>' should fail" '
96 +test_expect_success "'ipfs pin rm -r=false <hash>' should fail" '
97 echo "Error: $HASH is pinned recursively" >expected4 &&
90 - test_must_fail ipfs pin rm "$HASH" 2>actual4 &&
98 + test_must_fail ipfs pin rm -r=false "$HASH" 2>actual4 &&
99 test_cmp expected4 actual4
100 '
101
@@ -95,7 +103,7 @@ test_expect_success "remove recursive pin, add direct" '
103 echo "unpinned $HASH" >expected5 &&
104 ipfs pin rm -r "$HASH" >actual5 &&
105 test_cmp expected5 actual5 &&
98 - ipfs pin add "$HASH"
106 + ipfs pin add -r=false "$HASH"
107 '
108
109 test_expect_success "remove direct pin" '
@@ -142,7 +150,7 @@ test_expect_success "pin something directly" '
150 test_cmp expected9 actual9 &&
151
152 echo "pinned $DIRECTPIN directly" >expected10 &&
145 - ipfs pin add "$DIRECTPIN" >actual10 &&
153 + ipfs pin add -r=false "$DIRECTPIN" >actual10 &&
154 test_cmp expected10 actual10
155 '
156
test/sharness/t0081-repo-pinning.sh
+3 -3
@@ -190,9 +190,9 @@ test_expect_success "none are pinned any more" '
190 '
191
192 test_expect_success "pin some directly and indirectly" '
193 - ipfs pin add "$HASH_DIR1" >actual7 &&
194 - ipfs pin add -r "$HASH_DIR2" >>actual7 &&
195 - ipfs pin add "$HASH_FILE1" >>actual7 &&
193 + ipfs pin add -r=false "$HASH_DIR1" >actual7 &&
194 + ipfs pin add -r=true "$HASH_DIR2" >>actual7 &&
195 + ipfs pin add -r=false "$HASH_FILE1" >>actual7 &&
196 echo "pinned $HASH_DIR1 directly" >expected7 &&
197 echo "pinned $HASH_DIR2 recursively" >>expected7 &&
198 echo "pinned $HASH_FILE1 directly" >>expected7 &&