Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd `--force` flag to cargo install #2405
Conversation
rust-highfive
assigned
huonw
Feb 21, 2016
This comment has been minimized.
This comment has been minimized.
rust-highfive
commented
Feb 21, 2016
|
r? @huonw (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
rust-highfive
assigned
alexcrichton
and unassigned
huonw
Feb 21, 2016
This comment has been minimized.
This comment has been minimized.
|
Thanks for the PR @gkoz! There's a few technical aspects I'd tweak here, but I agree that the first thing to do here is probably to decide whether we want to do this in the first place. Let's discuss more on the issue, though, as that's probably the best place to have this discussion. (I'll write a comment over there shortly) |
gkoz
reviewed
Feb 23, 2016
| if replace { | ||
| return Ok(Some(p.clone())) | ||
| } | ||
| msg.push_str(&format!(" as part of `{}` (use --replace to override)", p)); | ||
| } | ||
| Err(human(msg)) |
This comment has been minimized.
This comment has been minimized.
gkoz
Feb 23, 2016
Author
Contributor
I've realized that it's safer to always list all conflicts when run without --replace thus the error should probably be generated somewhere up the stack.
This comment has been minimized.
This comment has been minimized.
|
There doesn't seem to be any opposition to this change. |
This comment has been minimized.
This comment has been minimized.
|
Ok, @wycats and I had a chance to talk about this recently, and this seems like it's desirable as it's pretty orthogonal from the One thought we had was perhaps this could be renamed |
This comment has been minimized.
This comment has been minimized.
|
Yes I'll keep You had mentioned some implementation issues. I'm guessing you don't like the |
This comment has been minimized.
This comment has been minimized.
|
Ah I believe what I had in mind was the "transactional" nature of the install. Right now the uninstall happens first, but it probably wants to get delayed until right before the actual new binaries are moved into place (either that or nothing is really uninstalled, just metadata is updated). |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
ping @gkoz, any update on this? |
This comment has been minimized.
This comment has been minimized.
|
Oh wow, it's been a month? I'll revisit this in a few days. |
This comment has been minimized.
This comment has been minimized.
|
Sounds good to me! Feel free to ping me if you need help pushing over the finish line. |
This comment has been minimized.
This comment has been minimized.
To avoid any misunderstanding... The current patch calls |
This comment has been minimized.
This comment has been minimized.
|
Basically what I'm getting at is two properties:
So given that, the error that I'm worried about here is that we successfully remove something but then hit an I/O error copying in a new file, In that case we won't restore the just-removed binaries. Could this be updated to handle that? |
gkoz
force-pushed the
gkoz:reinstall
branch
from
92515bd
to
eb1b581
Apr 15, 2016
This comment has been minimized.
This comment has been minimized.
|
I've pushed a version, that copies all binaries into a temp subdirectory of the destination and only after that succeeds tries to replace the existing binaries. If overwriting is partially successful, it doesn't try to undo anything (should it? that could further increase complexity) but still updates the metadata. Another difference from former behavior is (when Error handling is not ideal here:
Oh and I haven't tested on Windows yet to make sure there's no issue with |
gkoz
changed the title
Add `--replace` flag to cargo install
Add `--force` flag to cargo install
Apr 15, 2016
alexcrichton
reviewed
Apr 15, 2016
| } | ||
| } | ||
| } | ||
| // If `--bin` or `--example` weren't specified, uninstall obsolete |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Apr 15, 2016
Member
This seems a little surprising to me, this is basically saying if package A installed foo and bar, then B installed foo, you'd remove A's bar? I'd probably expect that A's bar stuck around and you could uninstall it with cargo uninstall A
This comment has been minimized.
This comment has been minimized.
gkoz
Apr 16, 2016
Author
Contributor
All this time I'd been assuming it's a good idea for cargo install -f foo to completely remove the remnants of the old package by default because that's probably what the user wants. :) If that's not the case I should probably add a hint "run 'cargo uninstall foo:{previous version}' to remove remaining binaries."
This comment has been minimized.
This comment has been minimized.
alexcrichton
Apr 16, 2016
Member
Hm yeah I guess it depends on how you look at it. On one hand you could have installed a package with a ton of binaries, some of which you never used, and then you overwrite one of the never used ones. On the other hand this could also hamstring a package to be useless if it's the one binary that counts.
To me though -f just means "do this anyway" which doesn't necessarily imply "do the extra work of removing everything else", and I like the idea of adding a note that other binaries from the package are lying around and may wish to be removed.
alexcrichton
reviewed
Apr 15, 2016
| @@ -27,23 +28,12 @@ struct CrateListingV1 { | |||
| v1: BTreeMap<PackageId, BTreeSet<String>>, | |||
| } | |||
|
|
|||
| struct Transaction { | |||
This comment has been minimized.
This comment has been minimized.
alexcrichton
Apr 15, 2016
Member
I think we may still want this transaction type in some form. Before we write out the metadata of new binaries if an error happens we need to remove them. If we overwrite something an then an error happens, it's fine to throw our hands up in the air
This comment has been minimized.
This comment has been minimized.
|
Thanks @gkoz! Can you also write some tests for some of the corner cases here? Just to make sure the metadata is managed properly and everything works as expected. |
alexcrichton
referenced this pull request
Apr 21, 2016
Closed
option for removing existing binary #2600
gkoz
force-pushed the
gkoz:reinstall
branch
from
eb1b581
to
dea80da
Apr 26, 2016
This comment has been minimized.
This comment has been minimized.
|
Still working on adding tests. Wondering how to imitate failure modes. Want to get this right first, and then add the hint about outdated binaries, possibly in another PR. |
This comment has been minimized.
This comment has been minimized.
|
It's ok to not necessarily exhaustively test them, it's fine to just smoke test a few simple ones like something already exists, a build failure when overwriting, etc. |
gkoz
added some commits
Apr 15, 2016
gkoz
force-pushed the
gkoz:reinstall
branch
from
dea80da
to
9f0fa24
Apr 30, 2016
This comment has been minimized.
This comment has been minimized.
|
Added more tests and an optional optimization in a separate commit. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
May 2, 2016
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors: retry On Mon, May 2, 2016 at 10:21 AM, bors notifications@github.com wrote:
|
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
|
gkoz commentedFeb 21, 2016
•
edited
Close #2082.
Adding
--force(-f) instructs cargo to overwrite existing binaries (updating the metadata accordingly).This allows updating crates via
cargo install -f <crate>.Installation happens in two stages now: binaries are copied into a temporary subdirectory of the destination first, then moved into destination. This should catch some errors earlier.
In case of installation error cargo will remove new binaries but won't attempt to undo successful overwrites.