Implement "repo rm-root" command to unlink the files API root.#4446
Implement "repo rm-root" command to unlink the files API root.#4446kevina wants to merge 4 commits into
Conversation
|
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. |
There was a problem hiding this comment.
maybe when no ipfs daemon is running
There was a problem hiding this comment.
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 := "" |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
if the err isnt empty, we probably shouldnt call .String() on the nil cid it returned
There was a problem hiding this comment.
Oops. That was suppose to be if err == nil.
|
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. |
Yes. It just assumes an empty root and start over. |
I am horrible at the wording for these things. Suggestions welcome. |
I added some text to the help text. Let me know if its what you are looking for. Suggestions welcome. |
|
This is good command to have a manual confirmation ( |
magik6k
left a comment
There was a problem hiding this comment.
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).
|
Yeah, I think some safety features might be good. Perhaps: |
8a9a19b to
a3c720e
Compare
|
@whyrusleeping I added the options as you suggested. |
ec87ec7 to
5ef87c2
Compare
| }, | ||
| } | ||
|
|
||
| var repoRmRootCmd = &cmds.Command{ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I see. So it's just a "last-ditch" fix my repo command. Got it.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
The documentation says "even if" not "only if" so I'd expect this case to work.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| } | ||
|
|
||
| // FilesRootKey returns the datastore key for the files root | ||
| func FilesRootKey() ds.Key { return ds.NewKey("/local/filesroot") } |
There was a problem hiding this comment.
I'd just make this a variable. I.e., var FilesRootKey ds.Key = ds.NewKey(...)
5ef87c2 to
089b8e8
Compare
|
Rebased. |
Closes #3934. License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
089b8e8 to
4ce7273
Compare
…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>
4ce7273 to
dc303d0
Compare
|
|
||
| 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) |
There was a problem hiding this comment.
API Sounds a bit confusing here IMO
| }, | ||
| } | ||
|
|
||
| var repoRmRootCmd = &cmds.Command{ |
There was a problem hiding this comment.
We may want something like this for pin root too, as it can be useful in similar situations
05aaf0c to
6c2b4c1
Compare
|
@magik6k I've renamed this to |
License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
6c2b4c1 to
784e0d8
Compare
|
Sharness seems to have failed on this: https://circleci.com/gh/ipfs/go-ipfs/14343?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link |
|
Superseded by #8648 |
Closes #3934.
Note I used the new API because the old API seams to initialize an
IpfsNodeeven ifcmds.Context.ConstructNode()is not called. (SettingdoesNotUseRepoand/ordoesNotUseConfigAsInputdid not seam to prevent the node initialization.)