mirror of
https://github.com/ovh/the-bastion.git
synced 2024-09-20 23:15:58 +08:00
fix: debian9: create_file_if_not_exists couldn't chgrp by filehanddle
This commit is contained in:
parent
69778815bb
commit
80ade2ba4c
|
@ -612,21 +612,30 @@ sub create_file_if_not_exists {
|
|||
my $ret = sysopen($fh, $file, O_RDWR | O_CREAT | O_EXCL);
|
||||
|
||||
if ($ret) {
|
||||
|
||||
# only if we did create the file:
|
||||
# - set the proper perms on it, if specified
|
||||
chmod($perms, $fh) if $perms;
|
||||
close($fh);
|
||||
|
||||
# - set the proper group, if specified
|
||||
if ($group) {
|
||||
my $gid = getgrnam($group);
|
||||
if (defined $gid) {
|
||||
chown -1, $gid, $fh;
|
||||
if (!chown -1, $gid, $file) {
|
||||
warn_syslog("Couldn't chgrp $file to group $group (GID $gid): $!");
|
||||
}
|
||||
}
|
||||
else {
|
||||
warn_syslog("Couldn't chgrp $file to group $group (no GID found)");
|
||||
}
|
||||
}
|
||||
|
||||
# only if we did create the file:
|
||||
# - set the proper perms on it, if specified
|
||||
if ($perms) {
|
||||
if (!chmod($perms, $file)) {
|
||||
warn_syslog("Couldn't chmod $file to perms $perms ($!)");
|
||||
}
|
||||
}
|
||||
|
||||
# done
|
||||
close($fh);
|
||||
return R('OK');
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue