Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install: fix absolute symbolic permissions #841

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use strict;
use File::Basename qw(basename dirname);
use Getopt::Std qw(getopts);

our $VERSION = '1.6';
our $VERSION = '1.7';
my $Program = basename($0);

sub VERSION_MESSAGE {
Expand Down Expand Up @@ -254,15 +254,15 @@ sub install_files {
next unless $Unix;
my $bits;
if ($symbolic) {
unless ( $bits = mod($mode, $targ) ) {
unless ( $bits = mod($mode, $file) ) {
die "$Program: invalid mode: $mode\n";
}
$bits = oct $bits;
}
else {
$bits = oct $mode;
}
modify_file $targ, $bits, \@st;
modify_file($targ, $bits, \@st);
}
}

Expand All @@ -278,26 +278,26 @@ sub install_files {
#
#

sub mod ($$) {
sub mod {
my $symbolic = shift;
my $file = shift;

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

my @ugo = qw/u g o/;
my %bits = ('s' => 8, 't' => 8, 'r' => 4, 'w' => 2, 'x' => 1);

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


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

my %perms;
Expand Down Expand Up @@ -382,7 +382,7 @@ sub mod ($$) {
next;
}
if ($operator eq '=') {
%perms = ( 'u' => 0, 'g' => 0, 'o' => 0);
$perms{$who} = 0;
}

# If we arrive here, $perms is a string.
Expand Down
Loading