Skip to content

Commit f7ec939

Browse files
Merge pull request #40 from theseus-rs/fix-parallel-extract
fix: correct parallel archive extract failures
2 parents ecf97d4 + 0015055 commit f7ec939

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

postgresql_archive/src/archive.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use reqwest_retry::policies::ExponentialBackoff;
1717
use reqwest_retry::RetryTransientMiddleware;
1818
use reqwest_tracing::TracingMiddleware;
1919
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};
2121
use std::io::{copy, BufReader, Cursor};
2222
use std::path::{Path, PathBuf};
2323
use 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

Comments
 (0)