Skip to content

Commit

Permalink
[rust] Check if file exists before unzipping
Browse files Browse the repository at this point in the history
  • Loading branch information
bonigarcia committed Aug 8, 2023
1 parent 353086e commit 712904c
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions rust/src/files.rs
Expand Up @@ -152,19 +152,21 @@ pub fn unzip(
));
create_parent_path_if_not_exists(out_path.as_path())?;

let mut outfile = File::create(&out_path)?;
io::copy(&mut file, &mut outfile)?;
unzipped_files += 1;

// Set permissions in Unix-like systems
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;

if single_file.is_some() {
fs::set_permissions(&out_path, fs::Permissions::from_mode(0o755))?;
} else if let Some(mode) = file.unix_mode() {
fs::set_permissions(&out_path, fs::Permissions::from_mode(mode))?;
if !out_path.exists() {
let mut outfile = File::create(&out_path)?;
io::copy(&mut file, &mut outfile)?;
unzipped_files += 1;

// Set permissions in Unix-like systems
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;

if single_file.is_some() {
fs::set_permissions(&out_path, fs::Permissions::from_mode(0o755))?;
} else if let Some(mode) = file.unix_mode() {
fs::set_permissions(&out_path, fs::Permissions::from_mode(mode))?;
}
}
}
}
Expand Down

0 comments on commit 712904c

Please sign in to comment.