Skip to content

Commit

Permalink
mkdir: make empty mode an error (#552)
Browse files Browse the repository at this point in the history
* Follow GNU & OpenBSD mkdir by failing early if the mode string (-m option-argument) was empty
* Previously -m '' was interpreted as -m 0
* Make one error message easier to read
  • Loading branch information
mknos committed Apr 14, 2024
1 parent fd78b39 commit 15e2360
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions bin/mkdir
Expand Up @@ -40,8 +40,12 @@ sub usage {
}

my $symbolic = 0;
if (exists $options{'m'} && $options{'m'} =~ /[^0-7]/) {
$symbolic = 1;
if (defined $options{'m'}) {
if (length($options{'m'}) == 0) {
warn "invalid mode\n";
exit EX_ERROR;
}
$symbolic = 1 if $options{'m'} =~ /[^0-7]/;
}

# Pay attention before you get lost. The argument list will be turned
Expand Down Expand Up @@ -74,7 +78,7 @@ foreach my $directory (@ARGV) {

# Umask is applied on mkdir.
mkdir $dir => 0777 or do {
warn qq 'cannot create make directory "$dir": $!\n';
warn "cannot create directory '$dir': $!\n";
$err++;
next;
};
Expand Down

0 comments on commit 15e2360

Please sign in to comment.