Skip to content

Commit 74eb448

Browse files
committed
Extract directory creation into its own function
1 parent 4aaad08 commit 74eb448

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

clippy_dev/src/lintcheck.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,7 @@ impl CrateSource {
115115
// url to download the crate from crates.io
116116
let url = format!("https://crates.io/api/v1/crates/{}/{}/download", name, version);
117117
println!("Downloading and extracting {} {} from {}", name, version, url);
118-
std::fs::create_dir("target/lintcheck/").unwrap_or_else(|err| {
119-
if err.kind() != ErrorKind::AlreadyExists {
120-
panic!("cannot create lintcheck target dir");
121-
}
122-
});
123-
std::fs::create_dir(&krate_download_dir).unwrap_or_else(|err| {
124-
if err.kind() != ErrorKind::AlreadyExists {
125-
panic!("cannot create crate download dir");
126-
}
127-
});
128-
std::fs::create_dir(&extract_dir).unwrap_or_else(|err| {
129-
if err.kind() != ErrorKind::AlreadyExists {
130-
panic!("cannot create crate extraction dir");
131-
}
132-
});
118+
create_dirs(&krate_download_dir, &extract_dir);
133119

134120
let krate_file_path = krate_download_dir.join(format!("{}-{}.crate.tar.gz", name, version));
135121
// 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
750736
});
751737
}
752738

739+
/// Create necessary directories to run the lintcheck tool.
740+
///
741+
/// # Panics
742+
///
743+
/// This function panics if creating one of the dirs fails.
744+
fn create_dirs(krate_download_dir: &Path, extract_dir: &Path) {
745+
std::fs::create_dir("target/lintcheck/").unwrap_or_else(|err| {
746+
if err.kind() != ErrorKind::AlreadyExists {
747+
panic!("cannot create lintcheck target dir");
748+
}
749+
});
750+
std::fs::create_dir(&krate_download_dir).unwrap_or_else(|err| {
751+
if err.kind() != ErrorKind::AlreadyExists {
752+
panic!("cannot create crate download dir");
753+
}
754+
});
755+
std::fs::create_dir(&extract_dir).unwrap_or_else(|err| {
756+
if err.kind() != ErrorKind::AlreadyExists {
757+
panic!("cannot create crate extraction dir");
758+
}
759+
});
760+
}
761+
753762
#[test]
754763
fn lintcheck_test() {
755764
let args = [

0 commit comments

Comments
 (0)