Skip to content
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

"No such file or directory" error after Cargo cache is deleted #26

Open
laniakea64 opened this issue Apr 5, 2024 · 2 comments · May be fixed by #27
Open

"No such file or directory" error after Cargo cache is deleted #26

laniakea64 opened this issue Apr 5, 2024 · 2 comments · May be fixed by #27

Comments

@laniakea64
Copy link

When the cache at $CARGO_HOME/registry has been deleted, using cargo-dl for any crate gives this error -

$ cargo dl cargo-dl
Error: could not acquire cargo-dl

Caused by:
    No such file or directory (os error 2)

Workaround: I have cargo-information installed, and after running cargo info on any crate, e.g. cargo info serde (does not need to be related to the crate to download), cargo-dl works again.

I'm using cargo-dl version 0.1.4 installed from crates.io.

Is it possible for cargo-dl to work with deleted cache?

Thanks 🙂

@Nemo157
Copy link
Member

Nemo157 commented Apr 6, 2024

Testing with debug logs:

> CARGO_DL_LOG=debug CARGO_HOME=$(mktemp -d) cargo dl cargo-dl
                                cargo-dl ⠉ querying index for cargo-dl                                                                                                                                                                                                            2024-04-06T16:20:47.334252Z DEBUG ureq::stream: connecting to index.crates.io:443 at [2600:9000:225a:d600:1f:a9f5:69c0:93a1]:443
    at crates.io/ureq-2.7.1/src/stream.rs:384

  2024-04-06T16:20:47.345774Z DEBUG rustls::client::hs: No cached session for DnsName("index.crates.io")
    at crates.io/rustls-0.21.6/src/client/hs.rs:73

  2024-04-06T16:20:47.345868Z DEBUG rustls::client::hs: Not resuming any session
    at crates.io/rustls-0.21.6/src/client/hs.rs:132

  2024-04-06T16:20:47.355191Z DEBUG rustls::client::hs: Using ciphersuite TLS13_AES_128_GCM_SHA256
    at crates.io/rustls-0.21.6/src/client/hs.rs:615

  2024-04-06T16:20:47.355224Z DEBUG rustls::client::tls13: Not resuming
    at crates.io/rustls-0.21.6/src/client/tls13.rs:142

  2024-04-06T16:20:47.355359Z DEBUG rustls::client::tls13: TLS1.3 encrypted extensions: [ServerNameAck]
    at crates.io/rustls-0.21.6/src/client/tls13.rs:381

  2024-04-06T16:20:47.355382Z DEBUG rustls::client::hs: ALPN protocol is None
    at crates.io/rustls-0.21.6/src/client/hs.rs:472

  2024-04-06T16:20:47.357054Z DEBUG ureq::stream: created stream: Stream(RustlsStream)
    at crates.io/ureq-2.7.1/src/stream.rs:199

  2024-04-06T16:20:47.357080Z DEBUG ureq::unit: sending request GET https://index.crates.io/ca/rg/cargo-dl
    at crates.io/ureq-2.7.1/src/unit.rs:261

  2024-04-06T16:20:47.357128Z DEBUG ureq::unit: writing prelude: GET /ca/rg/cargo-dl HTTP/1.1
Host: index.crates.io
cargo-protocol: version=1
accept: text/plain
accept-encoding: gzip,identity
User-Agent: cargo-dl/0.1.4
    at crates.io/ureq-2.7.1/src/unit.rs:480

  2024-04-06T16:20:47.368554Z DEBUG ureq::response: Chunked body in response
    at crates.io/ureq-2.7.1/src/response.rs:375

  2024-04-06T16:20:47.368657Z DEBUG ureq::unit: response 200 to GET https://index.crates.io/ca/rg/cargo-dl
    at crates.io/ureq-2.7.1/src/unit.rs:314

  2024-04-06T16:20:47.369000Z DEBUG ureq::stream: dropping stream: Stream(RustlsStream)
    at crates.io/ureq-2.7.1/src/stream.rs:319

                                cargo-dl ⠉ selecting version                                                                                                                                                                                                                      2024-04-06T16:20:47.371374Z DEBUG cargo_dl: all available versions: ["0.1.0", "0.1.1", "0.1.2", "0.1.3", "0.1.4"]
    at src/main.rs:177

  2024-04-06T16:20:47.371428Z DEBUG cargo_dl: matching versions: ["0.1.4", "0.1.3", "0.1.2", "0.1.1", "0.1.0"]
    at src/main.rs:204

                                cargo-dl ⠙ checking cache for cargo-dl 0.1.4                                                                                                                                                                                                      2024-04-06T16:20:47.371620Z DEBUG cargo_dl::cache: failed finding cached file for cargo-dl@0.1.4 in registry sparse+https://index.crates.io/

Caused by:
    0: finding cache dir for registry sparse+https://index.crates.io/
    1: cache dir /tmp/tmp.AUkiNeCyMp/registry/cache/index.crates.io-6f17d22bba15001f does not exist
    at src/cache.rs:88

  2024-04-06T16:20:47.371680Z DEBUG cargo_dl::cache: failed finding cached file for cargo-dl@0.1.4 in registry https://github.com/rust-lang/crates.io-index

Caused by:
    0: finding cache dir for registry https://github.com/rust-lang/crates.io-index
    1: cache dir /tmp/tmp.AUkiNeCyMp/registry/cache/github.com-1ecc6299db9ec823 does not exist
    at src/cache.rs:88

  2024-04-06T16:20:47.371710Z DEBUG cargo_dl: failed finding cached file for cargo-dl@0.1.4 in registries ["sparse+https://index.crates.io/", "https://github.com/rust-lang/crates.io-index"]
    at src/main.rs:283

Error: could not acquire cargo-dl

Caused by:
    No such file or directory (os error 2)

So it successfully does a query direct to the sparse index to detect which version, sees it's not available in the cache, but then fails.

With some extra local debugging the failure comes from index.index_config() when trying to lookup the download url, the file that must exist is $CARGO_HOME/registry/index/index.crates.io-6f17d22bba15001f/config.json:

let url = version.download_url(&index.index_config()?).context("missing download url")?;

There doesn't appear to be any way to do a query of the config from the remote with crates-index if it doesn't exist, I'll open an upstream issue about it and probably try to prepare a PR adding it.

@laniakea64
Copy link
Author

Thanks for investigating!

Since your PR to crates-index has been merged and released, I have been testing #27 patch to src/main.rs with using latest crates.io version of crates-index. Can confirm it fixes this issue 🎉

Any update on including this in cargo-dl?

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

Successfully merging a pull request may close this issue.

2 participants