commands/add: return an error when using --only-hash and --to-files
In that situation, the data is not written to permanent storage, so a reference in MFS would be to p2p blocks at best. The /add command in that situation is also likely to hang as it reads immediately the root node without being able to get it (it falls back to bitswap).
Michael Muré committed
Oct 19, 2023 at 16:00 UTC
eb7f6635145fb1be135d20b38585c7ec99c41fab
1 file changed
+6
-2
core/commands/add.go
+6
-2
@@ -194,7 +194,7 @@ See 'dag export' and 'dag import' for more information.
194
progress, _ := req.Options[progressOptionName].(bool)
195
trickle, _ := req.Options[trickleOptionName].(bool)
196
wrap, _ := req.Options[wrapOptionName].(bool)
197
- hash, _ := req.Options[onlyHashOptionName].(bool)
197
+ onlyHash, _ := req.Options[onlyHashOptionName].(bool)
198
silent, _ := req.Options[silentOptionName].(bool)
199
chunker, _ := req.Options[chunkerOptionName].(string)
200
dopin, _ := req.Options[pinOptionName].(bool)
@@ -207,6 +207,10 @@ See 'dag export' and 'dag import' for more information.
207
inlineLimit, _ := req.Options[inlineLimitOptionName].(int)
208
toFilesStr, toFilesSet := req.Options[toFilesOptionName].(string)
209
210
+ if onlyHash && toFilesSet {
211
+ return fmt.Errorf("%s and %s options are not compatible", onlyHashOptionName, toFilesOptionName)
212
+ }
213
+
214
hashFunCode, ok := mh.Names[strings.ToLower(hashFunStr)]
215
if !ok {
216
return fmt.Errorf("unrecognized hash function: %q", strings.ToLower(hashFunStr))
@@ -233,7 +237,7 @@ See 'dag export' and 'dag import' for more information.
237
options.Unixfs.Chunker(chunker),
238
239
options.Unixfs.Pin(dopin),
236
- options.Unixfs.HashOnly(hash),
240
+ options.Unixfs.HashOnly(onlyHash),
241
options.Unixfs.FsCache(fscache),
242
options.Unixfs.Nocopy(nocopy),
243