@@ -8,7 +8,7 @@ use std::time::Duration;
8
8
use serde:: Deserialize ;
9
9
use walkdir:: { DirEntry , WalkDir } ;
10
10
11
- use crate :: { Crate , LINTCHECK_DOWNLOADS , LINTCHECK_SOURCES } ;
11
+ use crate :: { Crate , lintcheck_sources , target_dir } ;
12
12
13
13
const DEFAULT_DOCS_LINK : & str = "https://docs.rs/{krate}/{version}/src/{krate_}/{file}.html#{line}" ;
14
14
const DEFAULT_GITHUB_LINK : & str = "{url}/blob/{hash}/src/{file}#L{line}" ;
@@ -201,8 +201,10 @@ impl CrateWithSource {
201
201
let file_link = & self . file_link ;
202
202
match & self . source {
203
203
CrateSource :: CratesIo { version } => {
204
- let extract_dir = PathBuf :: from ( LINTCHECK_SOURCES ) ;
205
- let krate_download_dir = PathBuf :: from ( LINTCHECK_DOWNLOADS ) ;
204
+ let extract_dir = PathBuf :: from ( lintcheck_sources ( ) ) ;
205
+ // Keep constant downloads path to avoid repeating work and
206
+ // filling up disk space unnecessarily.
207
+ let krate_download_dir = PathBuf :: from ( "target/lintcheck/downloads/" ) ;
206
208
207
209
// url to download the crate from crates.io
208
210
let url = format ! ( "https://crates.io/api/v1/crates/{name}/{version}/download" ) ;
@@ -211,7 +213,7 @@ impl CrateWithSource {
211
213
212
214
let krate_file_path = krate_download_dir. join ( format ! ( "{name}-{version}.crate.tar.gz" ) ) ;
213
215
// don't download/extract if we already have done so
214
- if !krate_file_path. is_file ( ) {
216
+ if !krate_file_path. is_file ( ) || !extract_dir . join ( format ! ( "{name}-{version}" ) ) . exists ( ) {
215
217
// create a file path to download and write the crate data into
216
218
let mut krate_dest = fs:: File :: create ( & krate_file_path) . unwrap ( ) ;
217
219
let mut krate_req = get ( & url) . unwrap ( ) . into_reader ( ) ;
@@ -236,7 +238,7 @@ impl CrateWithSource {
236
238
} ,
237
239
CrateSource :: Git { url, commit } => {
238
240
let repo_path = {
239
- let mut repo_path = PathBuf :: from ( LINTCHECK_SOURCES ) ;
241
+ let mut repo_path = PathBuf :: from ( lintcheck_sources ( ) ) ;
240
242
// add a -git suffix in case we have the same crate from crates.io and a git repo
241
243
repo_path. push ( format ! ( "{name}-git" ) ) ;
242
244
repo_path
@@ -286,7 +288,7 @@ impl CrateWithSource {
286
288
// copy path into the dest_crate_root but skip directories that contain a CACHEDIR.TAG file.
287
289
// The target/ directory contains a CACHEDIR.TAG file so it is the most commonly skipped directory
288
290
// as a result of this filter.
289
- let dest_crate_root = PathBuf :: from ( LINTCHECK_SOURCES ) . join ( name) ;
291
+ let dest_crate_root = PathBuf :: from ( lintcheck_sources ( ) ) . join ( name) ;
290
292
if dest_crate_root. exists ( ) {
291
293
println ! ( "Deleting existing directory at `{}`" , dest_crate_root. display( ) ) ;
292
294
fs:: remove_dir_all ( & dest_crate_root) . unwrap ( ) ;
@@ -326,15 +328,16 @@ impl CrateWithSource {
326
328
///
327
329
/// This function panics if creating one of the dirs fails.
328
330
fn create_dirs ( krate_download_dir : & Path , extract_dir : & Path ) {
329
- fs:: create_dir ( "target /lintcheck/") . unwrap_or_else ( |err| {
331
+ fs:: create_dir ( format ! ( "{} /lintcheck/", target_dir ( ) ) ) . unwrap_or_else ( |err| {
330
332
assert_eq ! (
331
333
err. kind( ) ,
332
334
ErrorKind :: AlreadyExists ,
333
335
"cannot create lintcheck target dir"
334
336
) ;
335
337
} ) ;
336
- fs:: create_dir ( krate_download_dir) . unwrap_or_else ( |err| {
337
- assert_eq ! ( err. kind( ) , ErrorKind :: AlreadyExists , "cannot create crate download dir" ) ;
338
+ fs:: create_dir_all ( krate_download_dir) . unwrap_or_else ( |err| {
339
+ // We are allowed to reuse download dirs
340
+ assert_ne ! ( err. kind( ) , ErrorKind :: AlreadyExists ) ;
338
341
} ) ;
339
342
fs:: create_dir ( extract_dir) . unwrap_or_else ( |err| {
340
343
assert_eq ! (
0 commit comments