Skip to content

Commit e93d6fb

Browse files
rukolahasserlidel
andauthored
feat: warn user when 'pin remote add' while offline (#8621)
* feat: add warning message when the local node is offline for remote pinning * feat: check is node is online * feat: add test in t0700-remotepin.sh * feat: use grep and fix the test * fix: print to stdout only when --enc=text This ensures we don't break JSON produced by --enc=json Co-authored-by: Marcin Rataj <[email protected]>
1 parent edb32ac commit e93d6fb

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

core/commands/pin/remotepin.go

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"io"
7+
"os"
78
"sort"
89
"strings"
910
"text/tabwriter"
@@ -185,6 +186,8 @@ NOTE: a comma-separated notation is supported in CLI for convenience:
185186
return err
186187
}
187188
opts = append(opts, pinclient.PinOpts.WithOrigins(addrs...))
189+
} else if isInBlockstore && !node.IsOnline && cmds.GetEncoding(req, cmds.Text) == cmds.Text {
190+
fmt.Fprintf(os.Stdout, "WARNING: the local node is offline and remote pinning may fail if there is no other provider for this CID\n")
188191
}
189192

190193
// Execute remote pin request

test/sharness/t0700-remotepin.sh

+8
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,14 @@ test_remote_pins() {
319319
test_remote_pins ""
320320

321321
test_kill_ipfs_daemon
322+
323+
WARNINGMESSAGE="WARNING: the local node is offline and remote pinning may fail if there is no other provider for this CID"
324+
325+
test_expect_success "'ipfs pin remote add' shows the warning message while offline" '
326+
test_expect_code 0 ipfs pin remote add --service=test_pin_svc --background $BASE_ARGS --name=name_a $HASH_A > actual &&
327+
test_expect_code 0 grep -q "$WARNINGMESSAGE" actual
328+
'
329+
322330
test_done
323331

324332
# vim: ts=2 sw=2 sts=2 et:

0 commit comments

Comments
 (0)