Skip to content
Closed
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
13 changes: 13 additions & 0 deletions core/commands/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type AddPinOutput struct {
}

const (
pinForceOptionName = "force"
pinRecursiveOptionName = "recursive"
pinProgressOptionName = "progress"
)
Expand Down Expand Up @@ -193,6 +194,7 @@ collected if needed. (By default, recursively. Use -r=false for direct pins.)
cmdkit.StringArg("ipfs-path", true, true, "Path to object(s) to be unpinned.").EnableStdin(),
},
Options: []cmdkit.Option{
cmdkit.BoolOption(pinForceOptionName, "f", "Ignore nonexistent pins"),
cmdkit.BoolOption(pinRecursiveOptionName, "r", "Recursively unpin the object linked to by the specified object(s).").WithDefault(true),
},
Type: PinOutput{},
Expand All @@ -216,7 +218,18 @@ collected if needed. (By default, recursively. Use -r=false for direct pins.)
return
}

force, _, err := req.Option(pinForceOptionName).Bool()
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
}

removed, err := corerepo.Unpin(n, api, req.Context(), req.Arguments(), recursive)
if force && err == pin.ErrNotPinned {
res.SetOutput(nil)
return
}

if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
Expand Down
10 changes: 7 additions & 3 deletions test/sharness/t0085-pins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ test_description="Test ipfs pinning operations"

. lib/test-lib.sh

RANDOM_HASH=Qme8uX5n9hn15pw9p6WcVKoziyyC9LXv4LEgvsmKMULjnV

test_pins() {
EXTRA_ARGS=$1
Expand All @@ -19,7 +20,8 @@ test_pins() {
HASH_D=$(echo "D" | ipfs add -q --pin=false) &&
HASH_E=$(echo "E" | ipfs add -q --pin=false) &&
HASH_F=$(echo "F" | ipfs add -q --pin=false) &&
HASH_G=$(echo "G" | ipfs add -q --pin=false)
HASH_G=$(echo "G" | ipfs add -q --pin=false) &&
HASH_TEST_UNPIN=$(echo "unpin" | ipfs add -q)
'

test_expect_success "put all those hashes in a file" '
Expand Down Expand Up @@ -56,6 +58,10 @@ test_pins() {
cat hashes | ipfs pin rm
'

test_expect_success "unpin non-existent hashes with force option" '
Copy link
Contributor

Choose a reason for hiding this comment

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

To make sure things are working right I would do

ipfs pin rm --force <invalid-hash> <valid-hash> <invalid-hash>

ipfs pin rm --force $RANDOM_HASH $HASH_TEST_UNPIN $RANDOM_HASH
'

test_expect_success "test pin update" '
ipfs pin add "$HASH_A" &&
ipfs pin ls > before_update &&
Expand All @@ -69,8 +75,6 @@ test_pins() {
'
}

RANDOM_HASH=Qme8uX5n9hn15pw9p6WcVKoziyyC9LXv4LEgvsmKMULjnV

test_pins_error_reporting() {
EXTRA_ARGS=$1

Expand Down