@@ -13,17 +13,64 @@ use anyhow::Context as _;
1313use cargo_util:: { paths, Sha256 } ;
1414use serde:: Deserialize ;
1515
16+ /// `DirectorySource` contains a number of crates on the file system. It was
17+ /// designed for representing vendored dependencies for `cargo vendor`.
18+ ///
19+ /// `DirectorySource` at this moment is just a root directory containing other
20+ /// directories, which contain the source files of packages. Assumptions would
21+ /// be made to determine if a directory should be included as a package of a
22+ /// directory source's:
23+ ///
24+ /// * Ignore directories starting with dot `.` (tend to be hidden).
25+ /// * Only when a `Cargo.toml` exists in a directory will it be included as
26+ /// a package. `DirectorySource` at this time only looks at one level of
27+ /// directories and never went deeper.
28+ /// * There must be a [`Checksum`] file `.cargo-checksum.json` file at the same
29+ /// level of `Cargo.toml` to ensure the integrity when a directory source was
30+ /// created (usually by `cargo vendor`). A failure to find or parse a single
31+ /// checksum results in a denial of loading any package in this source.
32+ /// * Otherwise, there is no other restrction of the name of directories. At
33+ /// this moment, it is `cargo vendor` that defines the layout and the name of
34+ /// each directory.
35+ ///
36+ /// The file tree of a directory source may look like:
37+ ///
38+ /// ```text
39+ /// [source root]
40+ /// ├── a-valid-crate/
41+ /// │ ├── src/
42+ /// │ ├── .cargo-checksum.json
43+ /// │ └── Cargo.toml
44+ /// ├── .ignored-a-dot-crate/
45+ /// │ ├── src/
46+ /// │ ├── .cargo-checksum.json
47+ /// │ └── Cargo.toml
48+ /// ├── skipped-no-manifest/
49+ /// │ ├── src/
50+ /// │ └── .cargo-checksum.json
51+ /// └── no-checksum-so-fails-the-entire-source-reading/
52+ /// └── Cargo.toml
53+ /// ```
1654pub struct DirectorySource < ' cfg > {
55+ /// The unique identifier of this source.
1756 source_id : SourceId ,
57+ /// The root path of this source.
1858 root : PathBuf ,
59+ /// Packages that this sources has discovered.
1960 packages : HashMap < PackageId , ( Package , Checksum ) > ,
2061 config : & ' cfg Config ,
2162 updated : bool ,
2263}
2364
65+ /// The checksum file to ensure the integrity of a package in a directory source.
66+ ///
67+ /// The file name is simply `.cargo-checksum.json`. The checksum algorithm as
68+ /// of now is SHA256.
2469#[ derive( Deserialize ) ]
2570struct Checksum {
71+ /// Checksum of the package. Normally it is computed from the `.crate` file.
2672 package : Option < String > ,
73+ /// Checksums of each source file.
2774 files : HashMap < String , String > ,
2875}
2976
0 commit comments