diff --git a/core/commands/add.go b/core/commands/add.go index 8dcdd92171a..c815a2e0c4b 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -288,10 +288,6 @@ 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)) @@ -377,11 +373,6 @@ 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 = "/" } @@ -405,7 +396,12 @@ See 'dag export' and 'dag import' for more information. return } // if MFS destination is a dir, append filename to the dir path - toFilesDst += gopath.Base(addit.Name()) + if wrap && toFilesSet { + // pathAdded.RootCid() is like the same thing as lastHash. See lastHash below in this file. + toFilesDst += gopath.Base(pathAdded.RootCid().String()) + } else { + toFilesDst += gopath.Base(addit.Name()) + } } // error if we try to overwrite a preexisting file destination diff --git a/docs/changelogs/v0.33.md b/docs/changelogs/v0.33.md index 5fafe08a7bc..34a02b9cb73 100644 --- a/docs/changelogs/v0.33.md +++ b/docs/changelogs/v0.33.md @@ -59,9 +59,9 @@ New repositories initialized with `flatfs` in `Datastore.Spec` will have `sync` The old default was overly conservative and caused performance issues in big repositories that did a lot of writes. There is usually no need to flush on every block write to disk before continuing. Setting this to false is safe as kubo will automatically flush writes to disk before and after performing critical operations like pinning. However, we still provide users with ability to set this to true to be extra-safe (at the cost of a slowdown when adding files in bulk). -#### `ipfs add --to-files` no longer works with `--wrap` +#### `ipfs add --to-files` works better 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)). +Onboarding files and directories with `ipfs add --to-files` now requires non-empty names. due to this, The `--to-files` and `--wrap` now adds the final/wrapped CID to MFS instead of a literal "." ([#10612](https://github.com/ipfs/kubo/issues/10612)). #### `ipfs --api` supports HTTPS RPC endpoints