Files
This chapter gives some pointers on where to start looking at Cargo's on-disk data file structures.
Layoutis the abstraction for thetargetdirectory. It handles locking the target directory, and providing paths to the parts inside. There is a separateLayoutfor each "target".Resolvecontains the contents of theCargo.lockfile. See theencodemodule for the differentCargo.lockformats.TomlManifestcontains the contents of theCargo.tomlfile. It is translated to aManifestobject for some simplification, and theManifestis stored in aPackage.- The
fingerprintmodule deals with the fingerprint information stored intarget/debug/.fingerprint. This tracks whether or not a crate needs to be rebuilt. cargo installtracks its installed files with some metadata in$CARGO_HOME. The metadata is managed in thecommon_for_install_and_uninstallmodule.- Git sources are cached in
$CARGO_HOME/git. The code for this cache is in thegitsource module. - Registries are cached in
$CARGO_HOME/registry. There are three parts, the index, the compressed.cratefiles, and the extracted sources of those crate files.- Management of the registry cache can be found in the
registrysource module. Note that this includes an on-disk cache as an optimization for accessing the git repository. - Saving of
.cratefiles is handled by theRemoteRegistry. - Extraction of
.cratefiles is handled by theRegistrySource. - There is a lock for the package cache. Code must be careful, because
this lock must be obtained manually. See
Config::acquire_package_cache_lock.
- Management of the registry cache can be found in the
Filesystems
Cargo tends to get run on a very wide array of file systems. Different file systems can have a wide range of capabilities, and Cargo should strive to do its best to handle them. Some examples of issues to deal with:
- Not all file systems support locking. Cargo tries to detect if locking is supported, and if not, will ignore lock errors. This isn't ideal, but it is difficult to deal with.
- The
fs::canonicalizefunction doesn't work on all file systems (particularly some Windows file systems). If that function is used, there should be a fallback if it fails. This function will also return\\?\style paths on Windows, which can have some issues (such as some tools not supporting them, or having issues with relative paths). - Timestamps can be unreliable. The
fingerprintmodule has a deeper discussion of this. One example is that Docker cache layers will erase the fractional part of the time stamp. - Symlinks are not always supported, particularly on Windows.