src/tools.rs - file_set_contents_full: only call fchmod when we pass permissions

So that we can use it to write into /etc/pve/ (which does not support chmod).
This commit is contained in:
Dietmar Maurer 2019-07-31 12:44:27 +02:00
parent cec17a3ec7
commit 953d5e1531
1 changed files with 5 additions and 3 deletions

View File

@ -197,10 +197,12 @@ pub fn file_set_contents_full<P: AsRef<Path>>(
stat::Mode::S_IRGRP | stat::Mode::S_IROTH stat::Mode::S_IRGRP | stat::Mode::S_IROTH
)); ));
if perm != None {
if let Err(err) = stat::fchmod(fd, mode) { if let Err(err) = stat::fchmod(fd, mode) {
let _ = unistd::unlink(tmp_path); let _ = unistd::unlink(tmp_path);
bail!("fchmod {:?} failed: {}", tmp_path, err); bail!("fchmod {:?} failed: {}", tmp_path, err);
} }
}
if owner != None || group != None { if owner != None || group != None {
if let Err(err) = fchown(fd, owner, group) { if let Err(err) = fchown(fd, owner, group) {