From 5397374ce030b5c0090ff6a0cf0941e4abb8f1ee Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Sat, 8 Aug 2020 11:40:52 +0200 Subject: [PATCH] Use new Crate::from_slice constructor --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- src/index/crates.rs | 10 +--------- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4880ba2fb..3f439d1d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -322,7 +322,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "crates-index" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "git2 0.13.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -356,7 +356,7 @@ dependencies = [ "base64 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "comrak 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "crates-index 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crates-index 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)", "crates-index-diff 7.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "criterion 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "dotenv 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3791,7 +3791,7 @@ dependencies = [ "checksum core-foundation 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" "checksum core-foundation-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" "checksum cpuid-bool 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" -"checksum crates-index 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "15467291e8911aa3e73b0e77d988362da1df7ac974c7189ab38b94b6f7edfa7e" +"checksum crates-index 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1df1045d54201422cb3a9910da25de7d59fbdad0d03cabd10e33ef592e12ae6d" "checksum crates-index-diff 7.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2e6bb290b5bb11353fbb46ca4c68ad2e8f54ab6674e4ee6a94c102054fdaf00f" "checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" "checksum criterion 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "70daa7ceec6cf143990669a04c7df13391d55fb27bd4079d252fca774ba244d8" diff --git a/Cargo.toml b/Cargo.toml index f9bd8cff7..7bef59428 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ edition = "2018" log = "0.4" regex = "1" structopt = "0.3" -crates-index = "0.15.0" +crates-index = "0.15.1" crates-index-diff = "7" reqwest = { version = "0.10.6", features = ["blocking", "json"] } # TODO: Remove blocking when async is ready semver = { version = "0.9", features = ["serde"] } diff --git a/src/index/crates.rs b/src/index/crates.rs index 7ebc89cb5..3fafd166a 100644 --- a/src/index/crates.rs +++ b/src/index/crates.rs @@ -1,6 +1,5 @@ use crates_index::Crate; use failure::ResultExt; -use std::io::{Seek, SeekFrom, Write}; pub(crate) struct Crates { repo: git2::Repository, @@ -18,23 +17,16 @@ impl Crates { .find_commit(self.repo.refname_to_id("refs/remotes/origin/master")?)? .tree()?; - // crates_index doesn't publicly expose their slice constructor, so need to write each blob - // to a file before loading it as a `Crate`. - let mut tmp = tempfile::NamedTempFile::new()?; - let mut result = Ok(()); tree.walk(git2::TreeWalkMode::PreOrder, |_, entry| { result = (|| { if let Some(blob) = entry.to_object(&self.repo)?.as_blob() { - tmp.write_all(blob.content())?; - if let Ok(krate) = Crate::new(tmp.path()) { + if let Ok(krate) = Crate::from_slice(blob.content()) { f(krate); } else { log::warn!("Not a crate '{}'", entry.name().unwrap()); } - tmp.as_file().set_len(0)?; - tmp.seek(SeekFrom::Start(0))?; } Result::<(), failure::Error>::Ok(()) })()