diff --git a/clippy_dev/src/lintcheck.rs b/clippy_dev/src/lintcheck.rs index 81b86481f57..f01f14eb458 100644 --- a/clippy_dev/src/lintcheck.rs +++ b/clippy_dev/src/lintcheck.rs @@ -115,21 +115,7 @@ fn download_and_extract(&self) -> Crate { // url to download the crate from crates.io let url = format!("https://crates.io/api/v1/crates/{}/{}/download", name, version); println!("Downloading and extracting {} {} from {}", name, version, url); - std::fs::create_dir("target/lintcheck/").unwrap_or_else(|err| { - if err.kind() != ErrorKind::AlreadyExists { - panic!("cannot create lintcheck target dir"); - } - }); - std::fs::create_dir(&krate_download_dir).unwrap_or_else(|err| { - if err.kind() != ErrorKind::AlreadyExists { - panic!("cannot create crate download dir"); - } - }); - std::fs::create_dir(&extract_dir).unwrap_or_else(|err| { - if err.kind() != ErrorKind::AlreadyExists { - panic!("cannot create crate extraction dir"); - } - }); + create_dirs(&krate_download_dir, &extract_dir); let krate_file_path = krate_download_dir.join(format!("{}-{}.crate.tar.gz", name, version)); // don't download/extract if we already have done so @@ -750,6 +736,29 @@ fn print_stats(old_stats: HashMap, new_stats: HashMap<&String, us }); } +/// Create necessary directories to run the lintcheck tool. +/// +/// # Panics +/// +/// This function panics if creating one of the dirs fails. +fn create_dirs(krate_download_dir: &Path, extract_dir: &Path) { + std::fs::create_dir("target/lintcheck/").unwrap_or_else(|err| { + if err.kind() != ErrorKind::AlreadyExists { + panic!("cannot create lintcheck target dir"); + } + }); + std::fs::create_dir(&krate_download_dir).unwrap_or_else(|err| { + if err.kind() != ErrorKind::AlreadyExists { + panic!("cannot create crate download dir"); + } + }); + std::fs::create_dir(&extract_dir).unwrap_or_else(|err| { + if err.kind() != ErrorKind::AlreadyExists { + panic!("cannot create crate extraction dir"); + } + }); +} + #[test] fn lintcheck_test() { let args = [