cargo icon indicating copy to clipboard operation
cargo copied to clipboard

Recover after crate extraction is interrupted

Open zoumi opened this issue 8 years ago • 7 comments

When I was running cargo build --release, my computer suddenly poweroff(cargo was downloading crate then). So,I restart my computer, run cargo build --release again. The error occur:

$ cargo build --release
error: unable to get packages from source

Caused by:
failed to download replaced source `registry https://github.com/rust-lang/crates.io-index`

Caused by:
failed to parse manifest at `/home/zoumi/.cargo/registry/src/mirrors.xxxx.com-      07d6cef1b9e54f94/syntex_errors-0.42.0/Cargo.toml`

Caused by:
no `package` or `project` section found.

It seem the file is broken, and cargo isn't able to recover. (Sorry for my poor english.)

zoumi avatar Feb 07 '17 10:02 zoumi

The file /syntex_errors-0.42.0/Cargo.toml is empty.

zoumi avatar Feb 07 '17 10:02 zoumi

If I delete the file, another error occur: error: unable to get packages from source

Caused by: failed to download replaced source registry https://github.com/rust-lang/crates.io-index

Caused by: failed to read /home/zoumi/.cargo/registry/src/mirrors.xxxx.com-07d6cef1b9e54f94/syntex_errors-0.42.0/Cargo.toml

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

How can I repaire my crate src? Delete /home/zoumi/.cargo/registry/src ?

zoumi avatar Feb 07 '17 10:02 zoumi

If it is not too bad for you (if you have a good internet connection and are OK with downloading all the crates again), you can just remove the $HOME/.cargo/registry/ and $HOME/.cargo/git/ directories.

Luthaf avatar Feb 07 '17 15:02 Luthaf

Curious!

As @Luthaf mentioned you can delete the whole registry folder and Cargo will recreate it. In theory this shouldn't happen as Cargo's hardened against failures like this, but there's perhaps a bug in those mitigations!

alexcrichton avatar Feb 07 '17 17:02 alexcrichton

It looks like I just experienced the same issue on Windows 10, with:

  • cargo 1.72.0 (103a7ff2e 2023-08-15)
  • rust-analyzer version: 0.3.1649-standalone (2df30e1e0 2023-09-03) (VS Code extension)

For me the PC crashed while rust-analyzer was building the project. After the PC restarted rust-analyzer failed to build the project.

For example:

Caused by:
  unable to get packages from source

Caused by:
  failed to download replaced source registry `crates-io`

Caused by:
  failed to parse manifest at `<user>\.cargo\registry\src\index.crates.io-6f17d22bba15001f\serde_json-1.0.106\Cargo.toml`

Caused by:
  could not parse input as TOML

Caused by:
  TOML parse error at line 1, column 1

That Cargo.toml file indeed seems to be corrupted and contains ~2KB of NUL bytes (and nothing else). There was also a Cargo.toml.orig file whose content seems to be correct wellformed TOML. And also a .cargo-ok and a .cargo_vcs_info.json file.

Running cargo clean followed by cargo test (which uses serde_json as dev-dependency) from the command line also causes this error.

Deleting those broken dependencies under <user>\.cargo\registry\src\index.crates.io-6f17d22bba15001f solved the issue.

Marcono1234 avatar Sep 10 '23 16:09 Marcono1234

The title of this issue is about interrupted downloads but the examples are for interrupted extractions which needs a separate solution.

Renaming accordingly.

epage avatar Aug 14 '24 14:08 epage

This was opened in 2017 and our solution to this has changed a lot since then, for a history of it see https://github.com/rust-lang/cargo/blob/c956e9f41c8a483385492b5b6c76cada8dd781cc/src/cargo/sources/registry/mod.rs#L551-L599 while we don't write the .cargo-ok file atomically, if its not a valid json file, we clear the cache and re- extract it.

What would be useful to know for anyone having problems with interruption recovery when extracting the files

  • what versions of rust are installed
  • the content of .cargo-ok

epage avatar Aug 19 '24 19:08 epage

Since we haven't heard of any more issues for this in the year since I asked for more information, I'm going to assume the fixes we put in since this was opened have addressed this and close it. If there is a reason for us to re-evaluate, let us know!

epage avatar Nov 06 '25 16:11 epage