Skip to content

Commit 71b95da

Browse files
committed
[rust] Ensure lock file exists and content of target folder after acquiring lock
1 parent bbaa951 commit 71b95da

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

rust/src/files.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ impl Lock {
9999
self.file.unlock().unwrap_or_default();
100100
fs::remove_file(&self.path).unwrap_or_default();
101101
}
102+
103+
fn exists(&mut self) -> bool {
104+
self.path.exists()
105+
}
102106
}
103107

104108
pub fn create_parent_path_if_not_exists(path: &Path) -> Result<(), Error> {
@@ -154,6 +158,19 @@ pub fn uncompress(
154158

155159
// Acquire file lock to prevent race conditions accessing the cache folder by concurrent SM processes
156160
let mut lock = Lock::acquire(log, target, single_file.clone())?;
161+
if !lock.exists() {
162+
let num_files_in_target = WalkDir::new(target).into_iter().count();
163+
if (single_file.is_some() && num_files_in_target == 1)
164+
|| (single_file.is_none() && num_files_in_target > 1)
165+
{
166+
log.trace(format!(
167+
"{} file(s) in {}",
168+
num_files_in_target,
169+
target.display()
170+
));
171+
return Ok(());
172+
}
173+
}
157174

158175
if extension.eq_ignore_ascii_case(ZIP) {
159176
unzip(compressed_file, target, log, single_file)?

0 commit comments

Comments
 (0)