Updated set_file_permissions

Allow custom permissions over target file
This commit is contained in:
fbsanchez 2016-10-31 12:32:45 +01:00
parent 12768e2d22
commit e559937697
1 changed files with 9 additions and 3 deletions

View File

@ -146,13 +146,19 @@ chomp($OS_VERSION);
###############################################################################
# Sets user:group owner for the given file
###############################################################################
sub set_file_permissions($$) {
my ($pa_config, $file) = @_;
sub set_file_permissions($$;$) {
my ($pa_config, $file, $grants) = @_;
if ($^O !~ /win/i ) { # Only for Linux environments
eval {
if (defined ($grants)) {
$grants = oct($grants);
}
else {
$grants = oct("0777");
}
my $uid = getpwnam($pa_config->{'user'});
my $gid = getgrnam($pa_config->{'group'});
my $perm = oct("0777") & (~oct($pa_config->{'umask'}));
my $perm = $grants & (~oct($pa_config->{'umask'}));
chown $uid, $gid, $file;
chmod ( $perm, $file );