about summary refs log tree commit diff
diff options
context:
space:
mode:
authorflip1995 <philipp.krones@embecosm.com>2021-03-05 14:06:43 +0100
committerflip1995 <philipp.krones@embecosm.com>2021-03-05 14:06:43 +0100
commit74eb44834cc12ce51396d94e98b04fdd0ad9bb64 (patch)
treec2deafa4b9c83d00f1b5150135f85cd2a4d1b6c7
parent4aaad086d2eff2d2f4e169551b6cffad22e7e751 (diff)
downloadrust-74eb44834cc12ce51396d94e98b04fdd0ad9bb64.tar.gz
rust-74eb44834cc12ce51396d94e98b04fdd0ad9bb64.zip
Extract directory creation into its own function
-rw-r--r--clippy_dev/src/lintcheck.rs39
1 files changed, 24 insertions, 15 deletions
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 @@ impl CrateSource {
                 // 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<String, usize>, 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 = [