@@ -17,7 +17,7 @@ use reqwest_retry::policies::ExponentialBackoff;
17
17
use reqwest_retry:: RetryTransientMiddleware ;
18
18
use reqwest_tracing:: TracingMiddleware ;
19
19
use sha2:: { Digest , Sha256 } ;
20
- use std:: fs:: { create_dir_all, remove_file, rename, File } ;
20
+ use std:: fs:: { create_dir_all, remove_dir_all , remove_file, rename, File } ;
21
21
use std:: io:: { copy, BufReader , Cursor } ;
22
22
use std:: path:: { Path , PathBuf } ;
23
23
use std:: str:: FromStr ;
@@ -390,14 +390,26 @@ pub async fn extract(bytes: &Bytes, out_dir: &Path) -> Result<()> {
390
390
}
391
391
}
392
392
393
- debug ! (
394
- "Renaming {} to {}" ,
395
- extract_dir. to_string_lossy( ) ,
396
- out_dir. to_string_lossy( )
397
- ) ;
398
- rename ( extract_dir, out_dir) ?;
399
- debug ! ( "Removing lock file: {}" , lock_file. to_string_lossy( ) ) ;
400
- remove_file ( lock_file) ?;
393
+ if out_dir. exists ( ) {
394
+ debug ! (
395
+ "Directory already exists {}; skipping name and removing extraction directory: {}" ,
396
+ out_dir. to_string_lossy( ) ,
397
+ extract_dir. to_string_lossy( )
398
+ ) ;
399
+ remove_dir_all ( & extract_dir) ?;
400
+ } else {
401
+ debug ! (
402
+ "Renaming {} to {}" ,
403
+ extract_dir. to_string_lossy( ) ,
404
+ out_dir. to_string_lossy( )
405
+ ) ;
406
+ rename ( extract_dir, out_dir) ?;
407
+ }
408
+
409
+ if lock_file. is_file ( ) {
410
+ debug ! ( "Removing lock file: {}" , lock_file. to_string_lossy( ) ) ;
411
+ remove_file ( lock_file) ?;
412
+ }
401
413
402
414
debug ! (
403
415
"Extracting {} files totalling {}" ,
0 commit comments