Skip to content

Commit

Permalink
commands/add: return an error when using --only-hash and --to-files
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
MichaelMure committed Oct 19, 2023
1 parent 4695fd9 commit 3306a4f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 197 in core/commands/add.go

View check run for this annotation

Codecov / codecov/patch

core/commands/add.go#L197

Added line #L197 was not covered by tests
silent, _ := req.Options[silentOptionName].(bool)
chunker, _ := req.Options[chunkerOptionName].(string)
dopin, _ := req.Options[pinOptionName].(bool)
Expand All @@ -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)
}

Check warning on line 212 in core/commands/add.go

View check run for this annotation

Codecov / codecov/patch

core/commands/add.go#L210-L212

Added lines #L210 - L212 were not covered by tests

hashFunCode, ok := mh.Names[strings.ToLower(hashFunStr)]
if !ok {
return fmt.Errorf("unrecognized hash function: %q", strings.ToLower(hashFunStr))
Expand All @@ -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),

Check warning on line 240 in core/commands/add.go

View check run for this annotation

Codecov / codecov/patch

core/commands/add.go#L240

Added line #L240 was not covered by tests
options.Unixfs.FsCache(fscache),
options.Unixfs.Nocopy(nocopy),

Expand Down

0 comments on commit 3306a4f

Please sign in to comment.