@@ -17,7 +17,7 @@ use reqwest_retry::policies::ExponentialBackoff;
1717use reqwest_retry:: RetryTransientMiddleware ;
1818use reqwest_tracing:: TracingMiddleware ;
1919use 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 } ;
2121use std:: io:: { copy, BufReader , Cursor } ;
2222use std:: path:: { Path , PathBuf } ;
2323use std:: str:: FromStr ;
@@ -390,14 +390,26 @@ pub async fn extract(bytes: &Bytes, out_dir: &Path) -> Result<()> {
390390 }
391391 }
392392
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+ }
401413
402414 debug ! (
403415 "Extracting {} files totalling {}" ,
0 commit comments