@@ -13,17 +13,64 @@ use anyhow::Context as _;
13
13
use cargo_util:: { paths, Sha256 } ;
14
14
use serde:: Deserialize ;
15
15
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
+ /// ```
16
54
pub struct DirectorySource < ' cfg > {
55
+ /// The unique identifier of this source.
17
56
source_id : SourceId ,
57
+ /// The root path of this source.
18
58
root : PathBuf ,
59
+ /// Packages that this sources has discovered.
19
60
packages : HashMap < PackageId , ( Package , Checksum ) > ,
20
61
config : & ' cfg Config ,
21
62
updated : bool ,
22
63
}
23
64
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.
24
69
#[ derive( Deserialize ) ]
25
70
struct Checksum {
71
+ /// Checksum of the package. Normally it is computed from the `.crate` file.
26
72
package : Option < String > ,
73
+ /// Checksums of each source file.
27
74
files : HashMap < String , String > ,
28
75
}
29
76
0 commit comments