Optimize fetch_crate_cratesio using ManifestVisitor

and `download_tar_based_and_visit`.

By using these two items, we avoid any I/O altogether.
Everything happens in memory, thus there will be no i/o related errors
or cost.

This commit does not regress anything because
`helpers::load_manifest_path` calls `Manifest::from_path_with_metadata`,
which read in the whole `Cargo.toml` file at once.

Thus this commit would not cause any OOM when the the original code
would not.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-06-12 16:37:53 +10:00
parent f3d3c488e3
commit 5bb5d12949
No known key found for this signature in database
GPG key ID: 591C0B03040416D6
2 changed files with 14 additions and 20 deletions

View file

@ -210,13 +210,14 @@ async fn entry() -> Result<()> {
// Fetch crate via crates.io, git, or use a local manifest path
// TODO: work out which of these to do based on `opts.name`
// TODO: support git-based fetches (whole repo name rather than just crate name)
let manifest_path = match opts.manifest_path.clone() {
Some(p) => p,
let manifest = match opts.manifest_path.clone() {
Some(manifest_path) => {
debug!("Reading manifest: {}", manifest_path.display());
load_manifest_path(manifest_path.join("Cargo.toml"))?
}
None => fetch_crate_cratesio(&opts.name, &opts.version, temp_dir.path()).await?,
};
debug!("Reading manifest: {}", manifest_path.display());
let manifest = load_manifest_path(manifest_path.join("Cargo.toml"))?;
let package = manifest.package.unwrap();
let is_plain_version = semver::Version::from_str(&opts.version).is_ok();