Skip to content

fix(cmds/add): disallow --wrap with --to-files - #10612

Merged
lidel merged 2 commits into
masterfrom
fix/10611-to-files-with-wrap
Dec 3, 2024
Merged

lidel merged 2 commits into
masterfrom
fix/10611-to-files-with-wrap

Conversation

@hsanjuan

@hsanjuan hsanjuan commented Dec 3, 2024

Copy link
Copy Markdown
Contributor

Fixes #10611.

When we are adding to an MFS folder ("--to-files=folder/"), we append the filename to the folder name.

However, when wrapping, the wrapping folder has no name and path.Base("") returns ..

This creates a folder named "." inside the previous one. But mfs operations like ls think that "." is the current folder, and does not contemplate the option of a folder of name ".".

Dealing with unnamed files in MFS is in general a footgun, so this commits attempts to prohibit that case.

@hsanjuan
hsanjuan requested a review from a team as a code owner December 3, 2024 16:40
Fixes #10611.

When we are adding to an MFS folder ("--to-files=folder/"), we append the filename to the folder name.

However, when wrapping, the wrapping folder has no name and `path.Base("")` returns `.`.

This creates a folder named "." inside the previous one. But mfs operations like `ls` think that "." is the current folder, and does not contemplate the option of a folder of name ".".

Dealing with unnamed files in MFS is in general a footgun, so this commits attempts to prohibit that case.
@hsanjuan
hsanjuan force-pushed the fix/10611-to-files-with-wrap branch from 9378dbb to b320438 Compare December 3, 2024 16:41
@lidel lidel mentioned this pull request Dec 3, 2024
51 of 60 tasks
@lidel lidel changed the title Add: disallow --wrap with --to-files fix(cmds/add): disallow --wrap with --to-files Dec 3, 2024

@lidel lidel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, sensible fix, added test to guard this.

Comment thread docs/changelogs/v0.33.md Outdated

### 📝 Changelog

- Fix: unnamed files in MFS. Disallow `--wrap` + `--to-files` when adding ([#10611](https://github.com/ipfs/kubo/issues/10611), [#10612](https://github.com/ipfs/kubo/issues/10612))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ @hsanjuan fysa the Changelo section is generated during Kubo release (we have cli tool that pulls commits/prs from kubo/boxo/go-libp2p etc), moved this to "Highlights" section.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!! Won't forget next time.

Comment on lines +472 to +480
# 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
'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ added basic regression test that guards this behavior

@lidel
lidel merged commit 433444b into master Dec 3, 2024
@lidel
lidel deleted the fix/10611-to-files-with-wrap branch December 3, 2024 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ipfs add: to-files with wrap creates literal single-character dot folders

3 participants