fix(cmds/add): disallow --wrap with --to-files (#10612)
Close #10611 Co-authored-by: Marcin Rataj <lidel@lidel.org>
Hector Sanjuan committed
Dec 3, 2024 at 21:49 UTC
433444b6097685b26843e517fb934782d56be99a
3 files changed
+27
-2
core/commands/add.go
+9
@@ -288,6 +288,10 @@ See 'dag export' and 'dag import' for more information.
288
return fmt.Errorf("%s and %s options are not compatible", onlyHashOptionName, toFilesOptionName)
289
}
290
291
+ if wrap && toFilesSet {
292
+ return fmt.Errorf("%s and %s options are not compatible", wrapOptionName, toFilesOptionName)
293
+ }
294
+
295
hashFunCode, ok := mh.Names[strings.ToLower(hashFunStr)]
296
if !ok {
297
return fmt.Errorf("unrecognized hash function: %q", strings.ToLower(hashFunStr))
@@ -373,6 +377,11 @@ See 'dag export' and 'dag import' for more information.
377
378
// creating MFS pointers when optional --to-files is set
379
if toFilesSet {
380
+ if addit.Name() == "" {
381
+ errCh <- fmt.Errorf("%s: cannot add unnamed files to MFS", toFilesOptionName)
382
+ return
383
+ }
384
+
385
if toFilesStr == "" {
386
toFilesStr = "/"
387
}
docs/changelogs/v0.33.md
+7
@@ -6,6 +6,9 @@
6
7
- [Overview](#overview)
8
- [🔦 Highlights](#-highlights)
9
+ - [Bitswap improvements from Boxo](#bitswap-improvements-from-boxo)
10
+ - [Using default `libp2p_rcmgr` metrics](#using-default-libp2p_rcmgr--metrics)
11
+ - [`ipfs add --to-files` no longer works with `--wrap`](#ipfs-add---to-files-no-longer-works-with---wrap)
12
- [📦️ Dependency updates](#-dependency-updates)
13
- [📝 Changelog](#-changelog)
14
- [👨👩👧👦 Contributors](#-contributors)
@@ -24,6 +27,10 @@ Bespoke rcmgr metrics [were removed](https://github.com/ipfs/kubo/pull/9947), Ku
27
This makes it easier to compare Kubo with custom implementations based on go-libp2p.
28
If you depended on removed ones, please fill an issue to add them to the upstream [go-libp2p](https://github.com/libp2p/go-libp2p).
29
30
+#### `ipfs add --to-files` no longer works with `--wrap`
31
+
32
+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)).
33
+
34
#### 📦️ Dependency updates
35
36
- update `boxo` to [v0.24.TODO](https://github.com/ipfs/boxo/releases/tag/v0.24.TODO)
test/sharness/t0040-add-and-cat.sh
+11
-2
@@ -355,10 +355,10 @@ test_add_cat_file() {
355
test_cmp expected actual
356
'
357
358
- test_must_fail "ipfs add with multiple files of same name but different dirs fails" '
358
+ test_expect_success "ipfs add with multiple files of same name but different dirs fails" '
359
mkdir -p mountdir/same-file/ &&
360
cp mountdir/hello.txt mountdir/same-file/hello.txt &&
361
- ipfs add mountdir/hello.txt mountdir/same-file/hello.txt >actual &&
361
+ test_expect_code 1 ipfs add mountdir/hello.txt mountdir/same-file/hello.txt >actual &&
362
rm mountdir/same-file/hello.txt &&
363
rmdir mountdir/same-file
364
'
@@ -469,6 +469,15 @@ test_add_cat_file() {
469
ipfs files rm -r --force /mfs
470
'
471
472
+ # confirm -w and --to-files are exclusive
473
+ # context: https://github.com/ipfs/kubo/issues/10611
474
+ test_expect_success "ipfs add -r -w dir --to-files /mfs/subdir5/ errors (-w and --to-files are exclusive)" '
475
+ ipfs files mkdir -p /mfs/subdir5 &&
476
+ test_expect_code 1 ipfs add -r -w test --to-files /mfs/subdir5/ >actual 2>&1 &&
477
+ test_should_contain "Error" actual &&
478
+ ipfs files rm -r --force /mfs
479
+ '
480
+
481
}
482
483
test_add_cat_5MB() {