@@ -8,7 +8,7 @@ use std::time::Duration;
88use serde:: Deserialize ;
99use walkdir:: { DirEntry , WalkDir } ;
1010
11- use crate :: { Crate , LINTCHECK_DOWNLOADS , LINTCHECK_SOURCES } ;
11+ use crate :: { Crate , lintcheck_sources , target_dir } ;
1212
1313const DEFAULT_DOCS_LINK : & str = "https://docs.rs/{krate}/{version}/src/{krate_}/{file}.html#{line}" ;
1414const DEFAULT_GITHUB_LINK : & str = "{url}/blob/{hash}/src/{file}#L{line}" ;
@@ -201,8 +201,10 @@ impl CrateWithSource {
201201 let file_link = & self . file_link ;
202202 match & self . source {
203203 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/" ) ;
206208
207209 // url to download the crate from crates.io
208210 let url = format ! ( "https://crates.io/api/v1/crates/{name}/{version}/download" ) ;
@@ -211,7 +213,7 @@ impl CrateWithSource {
211213
212214 let krate_file_path = krate_download_dir. join ( format ! ( "{name}-{version}.crate.tar.gz" ) ) ;
213215 // 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 ( ) {
215217 // create a file path to download and write the crate data into
216218 let mut krate_dest = fs:: File :: create ( & krate_file_path) . unwrap ( ) ;
217219 let mut krate_req = get ( & url) . unwrap ( ) . into_reader ( ) ;
@@ -236,7 +238,7 @@ impl CrateWithSource {
236238 } ,
237239 CrateSource :: Git { url, commit } => {
238240 let repo_path = {
239- let mut repo_path = PathBuf :: from ( LINTCHECK_SOURCES ) ;
241+ let mut repo_path = PathBuf :: from ( lintcheck_sources ( ) ) ;
240242 // add a -git suffix in case we have the same crate from crates.io and a git repo
241243 repo_path. push ( format ! ( "{name}-git" ) ) ;
242244 repo_path
@@ -286,7 +288,7 @@ impl CrateWithSource {
286288 // copy path into the dest_crate_root but skip directories that contain a CACHEDIR.TAG file.
287289 // The target/ directory contains a CACHEDIR.TAG file so it is the most commonly skipped directory
288290 // 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) ;
290292 if dest_crate_root. exists ( ) {
291293 println ! ( "Deleting existing directory at `{}`" , dest_crate_root. display( ) ) ;
292294 fs:: remove_dir_all ( & dest_crate_root) . unwrap ( ) ;
@@ -326,15 +328,16 @@ impl CrateWithSource {
326328///
327329/// This function panics if creating one of the dirs fails.
328330fn 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| {
330332 assert_eq ! (
331333 err. kind( ) ,
332334 ErrorKind :: AlreadyExists ,
333335 "cannot create lintcheck target dir"
334336 ) ;
335337 } ) ;
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 ) ;
338341 } ) ;
339342 fs:: create_dir ( extract_dir) . unwrap_or_else ( |err| {
340343 assert_eq ! (
0 commit comments