Cargo stores the source code of downloaded crates in $HOME/.cargo/registry/src
(or the appropriate $CARGO_HOME
directory). I get that each unique registry I use will create a separate directory, presumably to prevent conflicts.
What I don't understand is why the same repository would create multiple directories:
$ ls -ld ~/.cargo/registry/src/github.com-*
drwxr-xr-x 473 shep staff 16082 Dec 27 2015 ~/.cargo/registry/src/github.com-0a35038f75765ae4
drwxr-xr-x 1187 shep staff 40358 Feb 8 19:10 ~/.cargo/registry/src/github.com-1ecc6299db9ec823
drwxr-xr-x 380 shep staff 12920 Sep 11 12:16 ~/.cargo/registry/src/github.com-88ac128001ac3a9a
Presumably the hash that is appended to the end plays some role in this. What causes Cargo to create one of these directories? Will it ever go back to a previous directory and continue using it?
The hash is based on two fields: the kind of source (central repository, git reference, local path, etc.) and the source's URL.
Cargo used to delegate to rust-url's implementation of Hash
for Url
, which changed over time. Cargo's implementation was last changed in pull request 2737 in order to fix issue 1710; Cargo now hashes the URL string, rather than the Url
object, in order to produce a more stable hash that doesn't depend on rust-url's behavior.
Also, Cargo uses the now-deprecated SipHasher
as the hash function. Because it's deprecated, it's possible that Cargo might change to another hash function in the future (or SipHasher
might move to a crate and Cargo will use that, who knows).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With