-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
base: master
Are you sure you want to change the base?
Conversation
cc @keks on the comment about commands above |
core/commands/repo.go
Outdated
'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.
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
There was a problem hiding this comment.
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.
core/commands/repo.go
Outdated
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.
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
core/commands/repo.go
Outdated
c, err := cid.Cast(val.([]byte)) | ||
cidStr := "" | ||
if err != nil { | ||
cidStr = c.String() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
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 ( |
There was a problem hiding this 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).
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
core/commands/repo.go
Outdated
}, | ||
} | ||
|
||
var repoRmRootCmd = &cmds.Command{ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two nits
core/commands/repo.go
Outdated
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.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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") } |
There was a problem hiding this comment.
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(...)
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
core/commands/repo.go
Outdated
|
||
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.
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
core/commands/repo.go
Outdated
}, | ||
} | ||
|
||
var repoRmRootCmd = &cmds.Command{ |
There was a problem hiding this comment.
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
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 |
Closes #3934.
Note I used the new API because the old API seams to initialize an
IpfsNode
even ifcmds.Context.ConstructNode()
is not called. (SettingdoesNotUseRepo
and/ordoesNotUseConfigAsInput
did not seam to prevent the node initialization.)