From 3306a4ff3ae264f832e0c95c002bd604caecfd83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Thu, 19 Oct 2023 16:00:47 +0200 Subject: [PATCH] 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). --- core/commands/add.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/commands/add.go b/core/commands/add.go index bdde6cb41824..ee99cf0dc75a 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -194,7 +194,7 @@ See 'dag export' and 'dag import' for more information. progress, _ := req.Options[progressOptionName].(bool) trickle, _ := req.Options[trickleOptionName].(bool) wrap, _ := req.Options[wrapOptionName].(bool) - hash, _ := req.Options[onlyHashOptionName].(bool) + onlyHash, _ := req.Options[onlyHashOptionName].(bool) silent, _ := req.Options[silentOptionName].(bool) chunker, _ := req.Options[chunkerOptionName].(string) dopin, _ := req.Options[pinOptionName].(bool) @@ -207,6 +207,10 @@ See 'dag export' and 'dag import' for more information. inlineLimit, _ := req.Options[inlineLimitOptionName].(int) toFilesStr, toFilesSet := req.Options[toFilesOptionName].(string) + if onlyHash && toFilesSet { + return fmt.Errorf("%s and %s options are not compatible", onlyHashOptionName, toFilesOptionName) + } + hashFunCode, ok := mh.Names[strings.ToLower(hashFunStr)] if !ok { return fmt.Errorf("unrecognized hash function: %q", strings.ToLower(hashFunStr)) @@ -233,7 +237,7 @@ See 'dag export' and 'dag import' for more information. options.Unixfs.Chunker(chunker), options.Unixfs.Pin(dopin), - options.Unixfs.HashOnly(hash), + options.Unixfs.HashOnly(onlyHash), options.Unixfs.FsCache(fscache), options.Unixfs.Nocopy(nocopy),