crates icon indicating copy to clipboard operation
crates copied to clipboard

Automatically update the cargo registry

Open lnicola opened this issue 5 years ago • 12 comments

Is your feature request related to a problem? Please describe. When querying GitHub, crates would return fresh results every time, but with the disk registry we might show up old information.

Describe the solution you'd like We should try to update the cargo registry on startup and possible on user request (in case a user keeps open the editor for days or weeks).

Describe alternatives you've considered Do nothing.

Additional context It looks like there's no way to force cargo to update its registry. A workaround is to run cargo install lazy_static.

I'm not sure how the cargo path is picked now, but cargo might not be in PATH.

lnicola avatar May 24 '20 10:05 lnicola

Hi, Cargo has a spesific path for the registry. I check it first if it is not available GitHub is used.

const cargoHome = process.env.CARGO_HOME || path.resolve(os.homedir(), ".cargo/");
const gitDir = path.resolve(cargoHome, "registry/index/github.com-1ecc6299db9ec823/.git/");

Since it is a git repo , I think we can trigger a pull

serayuzgur avatar May 24 '20 15:05 serayuzgur

It's a bare clone, so I think we need git fetch (git pull errors out).

But it might be better to let cargo do its thing in case the pull is not enough or it needs to do more housekeeping in the future.

lnicola avatar May 24 '20 15:05 lnicola

It is just a version index. I think it will be ok but we can ask to the collaborators . For git pull it uses git pull https://github.com/rust-lang/crates.io.git as default.

serayuzgur avatar May 24 '20 15:05 serayuzgur

The cargo local index is refreshed on every command: cargo check cargo build,... So for an active developer it is always the actual situation. Also the command cargo update --dry-run updates the local cache of crates.io index. And writes to the standard output what crates have new versions for this cargo.toml/cargo.lock. But because of --dry-run it does not automatically change cargo.toml. It can be a fast start for sync and get "old version" in the same moment.

bestia-dev avatar May 26 '20 13:05 bestia-dev

cargo update --dry-run seems sweet.

lnicola avatar May 26 '20 13:05 lnicola

It takes some time, so is better to do this async. The standard output looks like this: image

bestia-dev avatar May 26 '20 13:05 bestia-dev

Thanks for the idea.So if it is already updated on every command do we really have to call update ?

serayuzgur avatar May 26 '20 17:05 serayuzgur

I don't think it's updated on every command:

$ cargo check
    Finished dev [unoptimized + debuginfo] target(s) in 0.32s
$ time cargo update --dry-run
    Updating crates.io index
    Updating libc v0.2.70 -> v0.2.71
    Updating proc-macro-hack v0.5.15 -> v0.5.16
    Updating proc-macro2 v1.0.15 -> v1.0.17
    Updating sha2 v0.8.1 -> v0.8.2
    Updating syn v1.0.23 -> v1.0.25
    Updating version_check v0.9.1 -> v0.9.2
warning: not updating lockfile due to dry run
cargo update --dry-run  0.34s user 0.04s system 14% cpu 2.599 total

lnicola avatar May 26 '20 17:05 lnicola

For the performance it has a big impact I think. What do you think ?

serayuzgur avatar May 26 '20 18:05 serayuzgur

Ideally it would run it in the background and refresh the display when it finishes (or when you open a Cargo.toml file). This way you'd see possibly stale results when opening the projects, but they would update after a couple of seconds.

lnicola avatar May 26 '20 19:05 lnicola

I read the long history of "not doing that" in Cargo and the index stability "not guaranteed" story. One temporary solution (probably long-time temporary) is: cargo install lazy_static or cargo update --dry-run to not go directly with the git git fetch https://github.com/rust-lang/crates.io-index refs/heads/master:refs/remotes/origin/master

bestia-dev avatar May 27 '20 09:05 bestia-dev

+1 for running this on the first .toml open in the current editor session. Maybe even delay the drawing of the symbol until the registry is updated (or some timeout is hit).

Currently I need to cargo update and then dry save the toml for the extension to reload and show the correct versions.

Christoph-AK avatar Feb 08 '22 14:02 Christoph-AK

Since there are many issues going related with this, we have our own index server now. No more local checks with v0.6.0

serayuzgur avatar Jul 14 '23 09:07 serayuzgur