Skip to content

Commit df3ae25

Browse files
committed
debugging - set the mode when creating the file
1 parent 84ed3e3 commit df3ae25

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

rust/src/files.rs

+23-8
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,36 @@ pub fn unzip(
150150
));
151151
create_parent_path_if_not_exists(out_path.as_path());
152152

153-
let mut outfile = File::create(&out_path)?;
154-
io::copy(&mut file, &mut outfile)?;
155-
unzipped_files += 1;
156-
157-
// Set permissions in Unix-like systems
153+
let mut outfile;
154+
// permissions must be set while creating the file in Unix-like systems, otherwise the filesystem might
155+
// report the old permissions for some milliseconds
158156
#[cfg(unix)]
159157
{
160-
use std::os::unix::fs::PermissionsExt;
158+
use std::os::unix::fs::OpenOptionsExt;
161159

162160
if single_file.is_some() {
163-
fs::set_permissions(&out_path, fs::Permissions::from_mode(0o755))?;
161+
outfile = fs::OpenOptions::new()
162+
.create(true)
163+
.write(true)
164+
.mode(0o755)
165+
.open(&out_path)?;
164166
} else if let Some(mode) = file.unix_mode() {
165-
fs::set_permissions(&out_path, fs::Permissions::from_mode(mode)).unwrap();
167+
outfile = fs::OpenOptions::new()
168+
.create(true)
169+
.write(true)
170+
.mode(mode)
171+
.open(&out_path)?;
172+
} else {
173+
outfile = File::create(&out_path)?;
166174
}
167175
}
176+
#[cfg(not(unix))]
177+
{
178+
outfile = File::create(&out_path)?;
179+
}
180+
181+
io::copy(&mut file, &mut outfile)?;
182+
unzipped_files += 1;
168183
}
169184
}
170185
if unzipped_files == 0 || (single_file.is_some() && unzipped_files != 1) {

0 commit comments

Comments
 (0)