[go: nahoru, domu]

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

Implement "repo rm-root" command to unlink the files API root. #4446

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

kevina
Copy link
Contributor
@kevina kevina commented Dec 1, 2017

Closes #3934.

Note I used the new API because the old API seams to initialize an IpfsNode even if cmds.Context.ConstructNode() is not called. (Setting doesNotUseRepo and/or doesNotUseConfigAsInput did not seam to prevent the node initialization.)

@whyrusleeping
Copy link
Member

cc @keks on the comment about commands above

'ipfs repo rm-root' will unlink the root used by the files API ('ipfs
files' commands) without trying to read the root itself. The root and
its children will then be removed by the garbage collector unless
pinned. This command can only run when no ipfs daemons are running.
Copy link
Member

Choose a reason for hiding this comment

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

maybe when no ipfs daemon is running

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just copied and pasted the text from ipfs repo fsck. But will fix.

cmds.EmitOnce(res, &MessageOutput{"Files API root not found.\n"})
default:
c, err := cid.Cast(val.([]byte))
cidStr := ""
Copy link
Member

Choose a reason for hiding this comment

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

i would use var cidStr string and declare it before calling cid.Cast

c, err := cid.Cast(val.([]byte))
cidStr := ""
if err != nil {
cidStr = c.String()
Copy link
Member

Choose a reason for hiding this comment

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

if the err isnt empty, we probably shouldnt call .String() on the nil cid it returned

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. That was suppose to be if err == nil.

@whyrusleeping
Copy link
Member

How does the daemon function when the files root is deleted? Does it just assume an empty root and start over?

Also, we should be very clear about why/when you would ever use this command in the helptext. Its basically only for extremely unfortunate circumstances.

@kevina
Copy link
Contributor Author
kevina commented Dec 3, 2017

How does the daemon function when the files root is deleted? Does it just assume an empty root and start over?

Yes. It just assumes an empty root and start over.

@kevina
Copy link
Contributor Author
kevina commented Dec 3, 2017

Also, we should be very clear about why/when you would ever use this command in the helptext. Its basically only for extremely unfortunate circumstances.

I am horrible at the wording for these things. Suggestions welcome.

@kevina kevina changed the title Implement "repo rm-root" command to unlike the files API root. Implement "repo rm-root" command to unlink the files API root. Dec 3, 2017
@kevina
Copy link
Contributor Author
kevina commented Dec 4, 2017

Also, we should be very clear about why/when you would ever use this command in the helptext. Its basically only for extremely unfortunate circumstances.

I added some text to the help text. Let me know if its what you are looking for. Suggestions welcome.

@Kubuxu
Copy link
Member
Kubuxu commented Dec 4, 2017

This is good command to have a manual confirmation (Y from stdin stream) with flag override but it might be hard to do with how currently the API works.

@whyrusleeping
Copy link
Member

@Kubuxu @magik6k wanna review this one?

It would probably be good to have manual confirmation as suggested, but maybe for the user to run it with a '--confirm' flag? Don't want to have to figure out how to do an interactive prompt as part of the changeset.

Copy link
Member
@magik6k magik6k left a comment

Choose a reason for hiding this comment

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

Something like --confirm would be nice. We could also check if the root node is present in the datastore and notify the user if it is (and possibly check if it is corrupted).

core/commands/repo.go Outdated Show resolved Hide resolved
@whyrusleeping
Copy link
Member

Yeah, I think some safety features might be good. Perhaps:

> ipfs repo rm-root
Error: this is a potentially dangerous operation please pass --confirm to proceed
> ipfs repo rm-root --confirm
Error: the root of your mfs directory exists locally. Are you sure you want to unlink this? pass --remote-existing-root to continue

@kevina kevina force-pushed the kevina/repo-recreate-root branch 2 times, most recently from 8a9a19b to a3c720e Compare May 30, 2018 19:35
@kevina
Copy link
Contributor Author
kevina commented May 30, 2018

@whyrusleeping I added the options as you suggested.

@kevina kevina force-pushed the kevina/repo-recreate-root branch 2 times, most recently from ec87ec7 to 5ef87c2 Compare June 4, 2018 07:08
},
}

var repoRmRootCmd = &cmds.Command{
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this belong in the ipfs files command tree? Also, I'd just call it ipfs files chroot and allow the user to change the root arbitrarily.

However, I may just be missing some context here.

Copy link
Member

Choose a reason for hiding this comment

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

We could even make it: ipfs files chroot --save /oldroot /newroot to allow saving the old root inside the new root. Actually, we might just want to do that by default to make this command less safer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't this belong in the ipfs files command tree?

@Stebalien this is meant to be a low level tool to deal with the case when the root node some how gets deleted and is not available anywhere. It is in repo because it a low level command. Like repo fsck or repo verify.

ipfs files chroot is an interesting idea, but more involved.

Copy link
Member

Choose a reason for hiding this comment

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

I see. So it's just a "last-ditch" fix my repo command. Got it.

Copy link
Member

Choose a reason for hiding this comment

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

We may want something like this for pin root too, as it can be useful in similar situations


// Can't use a full node as that interferes with the removal
// of the files root, so open the repo directly
repo, err := fsrepo.Open(configRoot)
Copy link
Member

Choose a reason for hiding this comment

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

That's... unfortunate. I run my daemon as a separate user. I'm fine with this as a temporary limitation, but we should fix it eventually.

Copy link
Member
@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

Two nits

res.SetError(fmt.Errorf("root %s exists locally. Are you sure you want to unlink this? Pass --remove-local-root to continue", cidStr), cmdkit.ErrNormal)
return
} else if !have && removeLocalRoot {
res.SetError(fmt.Errorf("root does not %s exists locally. Please remove --remove-local-root to continue", cidStr), cmdkit.ErrNormal)
Copy link
Member

Choose a reason for hiding this comment

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

The documentation says "even if" not "only if" so I'd expect this case to work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can fix the documentation. The idea behind this is to prevent this flag from automatically being passed. It is intentionally annoying. if this will Create a problem I can remove this check.

Copy link
Member

Choose a reason for hiding this comment

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

Reviving...

IMO, having to pass --confirm is annoying enough. If a user wants to automate this, that's their problem (and their choice).

I've switched this to act as documented unless someone objects.

core/core.go Outdated
@@ -743,8 +743,11 @@ func (n *IpfsNode) loadBootstrapPeers() ([]pstore.PeerInfo, error) {
return toPeerInfos(parsed), nil
}

// FilesRootKey returns the datastore key for the files root
func FilesRootKey() ds.Key { return ds.NewKey("/local/filesroot") }
Copy link
Member

Choose a reason for hiding this comment

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

I'd just make this a variable. I.e., var FilesRootKey ds.Key = ds.NewKey(...)

@ghost ghost assigned Stebalien Mar 2, 2019
@Stebalien
Copy link
Member

Rebased.

@Stebalien Stebalien requested a review from magik6k March 2, 2019 01:28
@Stebalien Stebalien added the need/review Needs a review label Mar 2, 2019
kevina and others added 2 commits March 1, 2019 17:30
Closes #3934.

License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
…cumentation

This command is already annoying enough. If a user decides to automate this,
that's their issue (and we should allow it).

(also rename back to remove-existing-root from remove-local-root)

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
core/commands/repo.go Outdated Show resolved Hide resolved

err = repo.Datastore().Delete(core.FilesRootKey)
if err != nil {
return fmt.Errorf("unable to remove API root: %s. Root hash was %s", err.Error(), cidStr)
Copy link
Member

Choose a reason for hiding this comment

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

API Sounds a bit confusing here IMO

},
}

var repoRmRootCmd = &cmds.Command{
Copy link
Member

Choose a reason for hiding this comment

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

We may want something like this for pin root too, as it can be useful in similar situations

@Stebalien
Copy link
Member

@magik6k I've renamed this to ipfs rm-files-root and improved the wording a bit.

@Stebalien Stebalien requested a review from magik6k March 4, 2019 21:15
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
@magik6k
Copy link
Member
magik6k commented Mar 5, 2019

@momack2 momack2 added this to In Progress in ipfs/go-ipfs May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need/review Needs a review status/in-progress In progress
Projects
No open projects
ipfs/go-ipfs
In Progress
Development

Successfully merging this pull request may close these issues.

IPFS Files root not avialable fix in 'ipfs repo fsck'
5 participants