From 9d4758cb5cebd929735d04c2f6e76b34b892441b Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Mon, 8 Jan 2024 11:43:44 +0100 Subject: [PATCH] feat(pinning): allow for overwriting pin name --- core/commands/pin/pin.go | 6 ++--- docs/examples/kubo-as-a-library/go.mod | 2 +- docs/examples/kubo-as-a-library/go.sum | 4 +-- go.mod | 2 +- go.sum | 4 +-- test/cli/pins_test.go | 34 ++++++++++++++++++++------ test/dependencies/go.mod | 2 +- test/dependencies/go.sum | 4 +-- 8 files changed, 38 insertions(+), 20 deletions(-) diff --git a/core/commands/pin/pin.go b/core/commands/pin/pin.go index d75d5d3865a..ca3c932bff0 100644 --- a/core/commands/pin/pin.go +++ b/core/commands/pin/pin.go @@ -71,10 +71,8 @@ Use 'pin ls -t recursive' to only list roots of recursively pinned DAGs (significantly faster when many big DAGs are pinned recursively) Default pin name is empty. Pass '--name' to 'pin add' to set one -and use 'pin ls --names' to see it. -Pin add is idempotent: pinning CID which is already pinned won't change -the name, value passed with '--name' with the original pin is preserved. -To rename pin, use 'pin rm' and 'pin add --name'. +and use 'pin ls --names' to see it. Pinning a second time with a different +name will update the name of the pin. If daemon is running, any missing blocks will be retrieved from the network. It may take some time. Pass '--progress' to track the progress. diff --git a/docs/examples/kubo-as-a-library/go.mod b/docs/examples/kubo-as-a-library/go.mod index 99cdca600cc..d3e438ca0d6 100644 --- a/docs/examples/kubo-as-a-library/go.mod +++ b/docs/examples/kubo-as-a-library/go.mod @@ -7,7 +7,7 @@ go 1.20 replace github.com/ipfs/kubo => ./../../.. require ( - github.com/ipfs/boxo v0.16.1-0.20240104131845-a391d0210287 + github.com/ipfs/boxo v0.16.1-0.20240109085802-d13d712f1c4e github.com/ipfs/kubo v0.0.0-00010101000000-000000000000 github.com/libp2p/go-libp2p v0.32.2 github.com/multiformats/go-multiaddr v0.12.0 diff --git a/docs/examples/kubo-as-a-library/go.sum b/docs/examples/kubo-as-a-library/go.sum index 59c684345aa..3f04634897f 100644 --- a/docs/examples/kubo-as-a-library/go.sum +++ b/docs/examples/kubo-as-a-library/go.sum @@ -261,8 +261,8 @@ github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c h1:7Uy github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c/go.mod h1:6EekK/jo+TynwSE/ZOiOJd4eEvRXoavEC3vquKtv4yI= github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs= github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0= -github.com/ipfs/boxo v0.16.1-0.20240104131845-a391d0210287 h1:My5Ct2+5I/+FN2HaFm3VCQB3Y+/A5kcWDGNS0JR1jo8= -github.com/ipfs/boxo v0.16.1-0.20240104131845-a391d0210287/go.mod h1:gCYL6EViui01M8Dr0cY8nOpRAbofxZDWASxbLSrG9Ac= +github.com/ipfs/boxo v0.16.1-0.20240109085802-d13d712f1c4e h1:GFMm0GO3tTLmjJ6uNZnTq0HpYV/kygZhe1sKYHQ/aVc= +github.com/ipfs/boxo v0.16.1-0.20240109085802-d13d712f1c4e/go.mod h1:gCYL6EViui01M8Dr0cY8nOpRAbofxZDWASxbLSrG9Ac= github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA= github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU= github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY= diff --git a/go.mod b/go.mod index 9212964c26a..134b16bd15b 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/hashicorp/go-multierror v1.1.1 github.com/ipfs-shipyard/nopfs v0.0.12-0.20231027223058-cde3b5ba964c github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c - github.com/ipfs/boxo v0.16.1-0.20240104131845-a391d0210287 + github.com/ipfs/boxo v0.16.1-0.20240109085802-d13d712f1c4e github.com/ipfs/go-block-format v0.2.0 github.com/ipfs/go-cid v0.4.1 github.com/ipfs/go-cidutil v0.1.0 diff --git a/go.sum b/go.sum index 927614d8b1d..4afe6d356f6 100644 --- a/go.sum +++ b/go.sum @@ -325,8 +325,8 @@ github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c h1:7Uy github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c/go.mod h1:6EekK/jo+TynwSE/ZOiOJd4eEvRXoavEC3vquKtv4yI= github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs= github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0= -github.com/ipfs/boxo v0.16.1-0.20240104131845-a391d0210287 h1:My5Ct2+5I/+FN2HaFm3VCQB3Y+/A5kcWDGNS0JR1jo8= -github.com/ipfs/boxo v0.16.1-0.20240104131845-a391d0210287/go.mod h1:gCYL6EViui01M8Dr0cY8nOpRAbofxZDWASxbLSrG9Ac= +github.com/ipfs/boxo v0.16.1-0.20240109085802-d13d712f1c4e h1:GFMm0GO3tTLmjJ6uNZnTq0HpYV/kygZhe1sKYHQ/aVc= +github.com/ipfs/boxo v0.16.1-0.20240109085802-d13d712f1c4e/go.mod h1:gCYL6EViui01M8Dr0cY8nOpRAbofxZDWASxbLSrG9Ac= github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA= github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU= github.com/ipfs/go-bitswap v0.11.0 h1:j1WVvhDX1yhG32NTC9xfxnqycqYIlhzEzLXG/cU1HyQ= diff --git a/test/cli/pins_test.go b/test/cli/pins_test.go index a57f1b89b08..415da8d3b6a 100644 --- a/test/cli/pins_test.go +++ b/test/cli/pins_test.go @@ -210,6 +210,10 @@ func TestPins(t *testing.T) { testPins(t, testPinsArgs{runDaemon: true, lsArg: "--stream", baseArg: "--cid-base=base32"}) }) + pinLs := func(node *harness.Node, args ...string) []string { + return strings.Split(node.IPFS(StrCat("pin", "ls", args)...).Stdout.Trimmed(), "\n") + } + t.Run("test pinning with names cli text output", func(t *testing.T) { t.Parallel() @@ -224,24 +228,40 @@ func TestPins(t *testing.T) { outBRegular := cidBStr + " recursive" outBDetailed := outBRegular + " testPin" - pinLs := func(args ...string) []string { - return strings.Split(node.IPFS(StrCat("pin", "ls", args)...).Stdout.Trimmed(), "\n") - } - - lsOut := pinLs("-t=recursive") + lsOut := pinLs(node, "-t=recursive") require.Contains(t, lsOut, outARegular) require.NotContains(t, lsOut, outADetailed) - lsOut = pinLs("-t=recursive", "--names") + lsOut = pinLs(node, "-t=recursive", "--names") require.Contains(t, lsOut, outADetailed) require.NotContains(t, lsOut, outARegular) _ = node.IPFS("pin", "update", cidAStr, cidBStr) - lsOut = pinLs("-t=recursive", "--names") + lsOut = pinLs(node, "-t=recursive", "--names") require.Contains(t, lsOut, outBDetailed) require.NotContains(t, lsOut, outADetailed) }) + t.Run("test overwriting pin with name", func(t *testing.T) { + t.Parallel() + + node := harness.NewT(t).NewNode().Init() + cidStr := node.IPFSAddStr(RandomStr(1000), "--pin=false") + + outBefore := cidStr + " recursive A" + outAfter := cidStr + " recursive B" + + _ = node.IPFS("pin", "add", "--name", "A", cidStr) + lsOut := pinLs(node, "-t=recursive", "--names") + require.Contains(t, lsOut, outBefore) + require.NotContains(t, lsOut, outAfter) + + _ = node.IPFS("pin", "add", "--name", "B", cidStr) + lsOut = pinLs(node, "-t=recursive", "--names") + require.Contains(t, lsOut, outAfter) + require.NotContains(t, lsOut, outBefore) + }) + // JSON that is also the wire format of /api/v0 t.Run("test pinning with names json output", func(t *testing.T) { t.Parallel() diff --git a/test/dependencies/go.mod b/test/dependencies/go.mod index d214f4f52a7..c788ea08120 100644 --- a/test/dependencies/go.mod +++ b/test/dependencies/go.mod @@ -103,7 +103,7 @@ require ( github.com/hexops/gotextdiff v1.0.3 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/ipfs/bbloom v0.0.4 // indirect - github.com/ipfs/boxo v0.16.1-0.20240104131845-a391d0210287 // indirect + github.com/ipfs/boxo v0.16.1-0.20240109085802-d13d712f1c4e // indirect github.com/ipfs/go-block-format v0.2.0 // indirect github.com/ipfs/go-cid v0.4.1 // indirect github.com/ipfs/go-datastore v0.6.0 // indirect diff --git a/test/dependencies/go.sum b/test/dependencies/go.sum index 91cdf538b85..186b0119246 100644 --- a/test/dependencies/go.sum +++ b/test/dependencies/go.sum @@ -342,8 +342,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2 github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs= github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0= -github.com/ipfs/boxo v0.16.1-0.20240104131845-a391d0210287 h1:My5Ct2+5I/+FN2HaFm3VCQB3Y+/A5kcWDGNS0JR1jo8= -github.com/ipfs/boxo v0.16.1-0.20240104131845-a391d0210287/go.mod h1:gCYL6EViui01M8Dr0cY8nOpRAbofxZDWASxbLSrG9Ac= +github.com/ipfs/boxo v0.16.1-0.20240109085802-d13d712f1c4e h1:GFMm0GO3tTLmjJ6uNZnTq0HpYV/kygZhe1sKYHQ/aVc= +github.com/ipfs/boxo v0.16.1-0.20240109085802-d13d712f1c4e/go.mod h1:gCYL6EViui01M8Dr0cY8nOpRAbofxZDWASxbLSrG9Ac= github.com/ipfs/go-block-format v0.2.0 h1:ZqrkxBA2ICbDRbK8KJs/u0O3dlp6gmAuuXUJNiW1Ycs= github.com/ipfs/go-block-format v0.2.0/go.mod h1:+jpL11nFx5A/SPpsoBn6Bzkra/zaArfSmsknbPMYgzM= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=