fix(commands/dht): pass values as files instead of arguments
Stdin can't have newlines, command-line arguments can't include null characters, DHT values can include both. This is a breaking change but this API has never worked anyways. fixes #5112
Steven Allen committed
Nov 5, 2019 at 17:54 UTC
32e891b78843c79fe75662ec8b1a83dc319f4afa
1 file changed
+14
-10
core/commands/dht.go
+14
-10
@@ -6,6 +6,7 @@ import (
6
"errors"
7
"fmt"
8
"io"
9
+ "io/ioutil"
10
"time"
11
12
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
@@ -515,8 +516,8 @@ var putValueDhtCmd = &cmds.Command{
516
Helptext: cmds.HelpText{
517
Tagline: "Write a key/value pair to the routing system.",
518
ShortDescription: `
518
-Given a key of the form /foo/bar and a value of any form, this will write that
519
-value to the routing system with that key.
519
+Given a key of the form /foo/bar and a valid value for that key, this will write
520
+that value to the routing system with that key.
521
522
Keys have two parts: a keytype (foo) and the key name (bar). IPNS uses the
523
/ipns keytype, and expects the key name to be a Peer ID. IPNS entries are
@@ -535,7 +536,7 @@ identified by QmFoo.
536
537
Arguments: []cmds.Argument{
538
cmds.StringArg("key", true, false, "The key to store the value at."),
538
- cmds.StringArg("value", true, false, "The value to store.").EnableStdin(),
539
+ cmds.FileArg("value", true, false, "The value to store.").EnableStdin(),
540
},
541
Options: []cmds.Option{
542
cmds.BoolOption(dhtVerboseOptionName, "v", "Print extra information."),
@@ -546,12 +547,6 @@ identified by QmFoo.
547
return err
548
}
549
549
- // Needed to parse stdin args.
550
- err = req.ParseBodyArgs()
551
- if err != nil {
552
- return err
553
- }
554
-
550
if !nd.IsOnline {
551
return ErrNotOnline
552
}
@@ -561,7 +556,16 @@ identified by QmFoo.
556
return err
557
}
558
564
- data := req.Arguments[1]
559
+ file, err := cmdenv.GetFileArg(req.Files.Entries())
560
+ if err != nil {
561
+ return err
562
+ }
563
+ defer file.Close()
564
+
565
+ data, err := ioutil.ReadAll(file)
566
+ if err != nil {
567
+ return err
568
+ }
569
570
ctx, cancel := context.WithCancel(req.Context)
571
ctx, events := routing.RegisterForQueryEvents(ctx)