Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Dec 3, 2024

Conversation

hsanjuan
Copy link
Contributor

@hsanjuan hsanjuan commented Dec 3, 2024

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.
@lidel lidel changed the title Add: disallow --wrap with --to-files fix(cmds/add): disallow --wrap with --to-files Dec 3, 2024
Copy link
Member

@lidel lidel left a comment

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.

@@ -32,6 +39,4 @@ If you depended on removed ones, please fill an issue to add them to the upstrea

### 📝 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
Member

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
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
Member

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
14 checks passed
@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