Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Automatically update the cargo registry #81

Closed
lnicola opened this issue May 24, 2020 · 13 comments
Closed

Automatically update the cargo registry #81

lnicola opened this issue May 24, 2020 · 13 comments

Comments

@lnicola
Copy link

lnicola commented May 24, 2020

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.

@serayuzgur
Copy link
Owner

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/git.luolix.top-1ecc6299db9ec823/.git/");

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

@lnicola
Copy link
Author

lnicola commented May 24, 2020

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.

@serayuzgur
Copy link
Owner

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.

@bestia-dev
Copy link

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.

@lnicola
Copy link
Author

lnicola commented May 26, 2020

cargo update --dry-run seems sweet.

@bestia-dev
Copy link

bestia-dev commented May 26, 2020

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

@serayuzgur
Copy link
Owner

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

@lnicola
Copy link
Author

lnicola commented May 26, 2020

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

@serayuzgur
Copy link
Owner

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

@lnicola
Copy link
Author

lnicola commented May 26, 2020

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.

@bestia-dev
Copy link

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

@Christoph-AK
Copy link

+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.

@serayuzgur
Copy link
Owner

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants