Skip to content

Commit

Permalink
fix(cmds/add): disallow --wrap with --to-files (#10612)
Browse files Browse the repository at this point in the history
Close #10611
Co-authored-by: Marcin Rataj <lidel@lidel.org>
  • Loading branch information
hsanjuan authored Dec 3, 2024
1 parent 224d6a3 commit 433444b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
9 changes: 9 additions & 0 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ See 'dag export' and 'dag import' for more information.
return fmt.Errorf("%s and %s options are not compatible", onlyHashOptionName, toFilesOptionName)
}

if wrap && toFilesSet {
return fmt.Errorf("%s and %s options are not compatible", wrapOptionName, toFilesOptionName)
}

hashFunCode, ok := mh.Names[strings.ToLower(hashFunStr)]
if !ok {
return fmt.Errorf("unrecognized hash function: %q", strings.ToLower(hashFunStr))
Expand Down Expand Up @@ -373,6 +377,11 @@ See 'dag export' and 'dag import' for more information.

// creating MFS pointers when optional --to-files is set
if toFilesSet {
if addit.Name() == "" {
errCh <- fmt.Errorf("%s: cannot add unnamed files to MFS", toFilesOptionName)
return
}

if toFilesStr == "" {
toFilesStr = "/"
}
Expand Down
7 changes: 7 additions & 0 deletions docs/changelogs/v0.33.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

- [Overview](#overview)
- [πŸ”¦ Highlights](#-highlights)
- [Bitswap improvements from Boxo](#bitswap-improvements-from-boxo)
- [Using default `libp2p_rcmgr` metrics](#using-default-libp2p_rcmgr--metrics)
- [`ipfs add --to-files` no longer works with `--wrap`](#ipfs-add---to-files-no-longer-works-with---wrap)
- [πŸ“¦οΈ Dependency updates](#-dependency-updates)
- [πŸ“ Changelog](#-changelog)
- [πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦ Contributors](#-contributors)
Expand All @@ -24,6 +27,10 @@ Bespoke rcmgr metrics [were removed](https://github.com/ipfs/kubo/pull/9947), Ku
This makes it easier to compare Kubo with custom implementations based on go-libp2p.
If you depended on removed ones, please fill an issue to add them to the upstream [go-libp2p](https://github.com/libp2p/go-libp2p).

#### `ipfs add --to-files` no longer works with `--wrap`

Onboarding files and directories with `ipfs add --to-files` now requires non-empty names. due to this, The `--to-files` and `--wrap` options are now mutually exclusive ([#10612](https://github.com/ipfs/kubo/issues/10612)).

#### πŸ“¦οΈ Dependency updates

- update `boxo` to [v0.24.TODO](https://github.com/ipfs/boxo/releases/tag/v0.24.TODO)
Expand Down
13 changes: 11 additions & 2 deletions test/sharness/t0040-add-and-cat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,10 @@ test_add_cat_file() {
test_cmp expected actual
'

test_must_fail "ipfs add with multiple files of same name but different dirs fails" '
test_expect_success "ipfs add with multiple files of same name but different dirs fails" '
mkdir -p mountdir/same-file/ &&
cp mountdir/hello.txt mountdir/same-file/hello.txt &&
ipfs add mountdir/hello.txt mountdir/same-file/hello.txt >actual &&
test_expect_code 1 ipfs add mountdir/hello.txt mountdir/same-file/hello.txt >actual &&
rm mountdir/same-file/hello.txt &&
rmdir mountdir/same-file
'
Expand Down Expand Up @@ -469,6 +469,15 @@ test_add_cat_file() {
ipfs files rm -r --force /mfs
'

# confirm -w and --to-files are exclusive
# context: https://github.com/ipfs/kubo/issues/10611
test_expect_success "ipfs add -r -w dir --to-files /mfs/subdir5/ errors (-w and --to-files are exclusive)" '
ipfs files mkdir -p /mfs/subdir5 &&
test_expect_code 1 ipfs add -r -w test --to-files /mfs/subdir5/ >actual 2>&1 &&
test_should_contain "Error" actual &&
ipfs files rm -r --force /mfs
'

}

test_add_cat_5MB() {
Expand Down

0 comments on commit 433444b

Please sign in to comment.