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

feat(command): add force flag for files rm #5555

Merged
merged 2 commits into from
Oct 5, 2018

Conversation

overbool
Copy link
Contributor

@overbool overbool commented Oct 3, 2018

Refer to: #5538 (comment), #5554

License: MIT
Signed-off-by: Overbool [email protected]

@@ -1002,6 +1002,7 @@ Remove files or directories.
},
Options: []cmdkit.Option{
cmdkit.BoolOption("recursive", "r", "Recursively remove directories."),
cmdkit.BoolOption("force", "Allow to remove anything else"),
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think of forcibly remove target at path; implies -r for directories as a description?

@overbool overbool force-pushed the feat/add-force-flag-for-files-rm branch from 16b8423 to 9895922 Compare October 4, 2018 14:39
License: MIT
Signed-off-by: Overbool <[email protected]>
@overbool overbool force-pushed the feat/add-force-flag-for-files-rm branch from 9895922 to bd23e7d Compare October 4, 2018 14:41
@overbool overbool changed the title WIP: feat(command): add force flag for files rm feat(command): add force flag for files rm Oct 4, 2018
License: MIT
Signed-off-by: Overbool <[email protected]>
@overbool
Copy link
Contributor Author

overbool commented Oct 4, 2018

@schomatis could u help me review this pr?

But I have a question about command option: when i add -f to option( cmdkit.BoolOption("force", "f", "Forcibly remove target at path; implies -r for directories") ) and use ipfs files rm -f ..., it will print the error Error: option name "f" used multiple times.

@schomatis
Copy link
Contributor

The -f short flag is already used for the global flush flag,

https://github.com/ipfs/go-ipfs/blob/a86cde50de4bd8da0b5eaf6f1936269bafd29c8e/core/commands/files.go#L56,

but that's ok, I actually prefer to just have the long explicit --force flag since this should be used with care and (hopefully) not too often.

switch childi.(type) {
dashr, _, _ := req.Option("r").Bool()

switch child.(type) {
case *mfs.Directory:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we can now turn this single-case switch into an if

@@ -629,6 +629,20 @@ test_files_api() {
test_expect_success "repo gc $EXTRA" '
ipfs repo gc
'

# test rm
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to add a test with an actual corrupted node, which could just be an empty proto-node, but I'm not sure how could we add that to MFS, ipfs files cp does check the type:

ipfs object new
# QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n
ipfs files cp /ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n /corrupted
# Error: cp: cannot flush the created file /corrupted: proto: required field "Type" not set

Copy link
Contributor

@schomatis schomatis Oct 4, 2018

Choose a reason for hiding this comment

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

Oh, turn off flush:

ipfs files -f=0 cp /ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n /corrupted
ipfs files rm /corrupted
# Error: proto: required field "Type" not set

Copy link
Contributor

Choose a reason for hiding this comment

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

OT: What's the difference of adding a file in MFS without flushing? I still don't know how that works (and I'm supposedly the one in charge of reviewing the MFS API 😬)

Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking about this some more, after adding the checks to PutNode this won't work anyways (even with flush turned off), so scratch that, I'm fine with the existing tests.

Copy link
Contributor

@schomatis schomatis left a comment

Choose a reason for hiding this comment

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

LGTM

@Stebalien Stebalien merged commit 05b3b81 into ipfs:master Oct 5, 2018
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.

4 participants