Skip to content

Commit 19934f9

Browse files
authored
install: fix absolute symbolic permissions (#841)
* When using '=' with 'install -m", the resulting file permissions weren't right; here's what I found... * mod() should be passed the original file to stat(), but it was being passed the target file after File::Copy::copy() created it * Base permissions for "absolute" symbolic permissions (i.e. those set with '=') are zero, so it is not correct to stat() the original file in this case * The statement clearing bits in perms-hash for operator '=' in loop should only clear bits for $who the current iteration looks at %perl install -m u=rwx,g=rx,o=x comm a/comm # -m 751 %perl install -m u=rwx,g=r comm a/comm # -m 740 %perl perl install -m 'a=' comm a/comm # -m 0
1 parent 059fa13 commit 19934f9

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

bin/install

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use strict;
1717
use File::Basename qw(basename dirname);
1818
use Getopt::Std qw(getopts);
1919

20-
our $VERSION = '1.6';
20+
our $VERSION = '1.7';
2121
my $Program = basename($0);
2222

2323
sub VERSION_MESSAGE {
@@ -254,15 +254,15 @@ sub install_files {
254254
next unless $Unix;
255255
my $bits;
256256
if ($symbolic) {
257-
unless ( $bits = mod($mode, $targ) ) {
257+
unless ( $bits = mod($mode, $file) ) {
258258
die "$Program: invalid mode: $mode\n";
259259
}
260260
$bits = oct $bits;
261261
}
262262
else {
263263
$bits = oct $mode;
264264
}
265-
modify_file $targ, $bits, \@st;
265+
modify_file($targ, $bits, \@st);
266266
}
267267
}
268268

@@ -278,26 +278,26 @@ sub install_files {
278278
#
279279
#
280280

281-
sub mod ($$) {
281+
sub mod {
282282
my $symbolic = shift;
283283
my $file = shift;
284284

285-
# Initialization.
286-
# The 'user', 'group' and 'other' groups.
287-
my @ugo = qw /u g o/;
288-
# Bit masks for '[sg]uid', 'sticky', 'read', 'write' and 'execute'.
289-
# Can't use qw // cause silly Perl doesn't know '2' is a number
290-
# when dealing with &= ~$bit.
291-
my %bits = (s => 8, t => 8, r => 4, w => 2, x => 1);
292-
285+
my @ugo = qw/u g o/;
286+
my %bits = ('s' => 8, 't' => 8, 'r' => 4, 'w' => 2, 'x' => 1);
293287

294288
# For parsing.
295289
my $who_re = '[augo]*';
296290
my $action_re = '[-+=][rstwxXugo]*';
297291

298292

299293
# Find the current permissions. This is what we start with.
300-
my $mode = sprintf "%04o" => (stat $file) [2] || 0;
294+
my $mode = '000';
295+
if ($symbolic =~ m/[\-\+]/) {
296+
my @st = stat $file;
297+
if (@st) {
298+
$mode = sprintf '%04o', $st[2];
299+
}
300+
}
301301
my $current = substr $mode => -3; # rwx permissions for ugo.
302302

303303
my %perms;
@@ -382,7 +382,7 @@ sub mod ($$) {
382382
next;
383383
}
384384
if ($operator eq '=') {
385-
%perms = ( 'u' => 0, 'g' => 0, 'o' => 0);
385+
$perms{$who} = 0;
386386
}
387387

388388
# If we arrive here, $perms is a string.

0 commit comments

Comments
 (0)