parsort: Fail if TMPDIR does not exist.

This commit is contained in:
Ole Tange 2021-07-09 18:39:01 +02:00
parent 35f539696e
commit 373e5cccc9
2 changed files with 88 additions and 5 deletions

View file

@ -121,7 +121,7 @@ GetOptions(
"help" => \$opt::dummy,
) || exit(255);
$Global::progname = ($0 =~ m:(^|/)([^/]+)$:)[1];
$Global::version = 20210622;
$Global::version = 20210623;
if($opt::version) { version(); exit 0; }
@Global::sortoptions =
shell_quote(@ARGV_before[0..($#ARGV_before-$#ARGV-1)]);
@ -174,7 +174,8 @@ sub sort_stdin {
map { mkfifo($_,0600) } @fifos;
# This trick removes the fifo as soon as it is connected in the other end
# (rm fifo; ...) < fifo
my @cmd = map { "(rm $_; sort @Global::sortoptions) < $_" } @fifos;
my @cmd = (map { "(rm $_; sort @Global::sortoptions) < $_" }
map { Q($_) } @fifos);
@cmd = merge(@cmd);
if(fork) {
} else {
@ -196,11 +197,13 @@ sub tmpname {
my($tmpname);
if(not -w $ENV{'TMPDIR'}) {
if(not -e $ENV{'TMPDIR'}) {
::error("Tmpdir '$ENV{'TMPDIR'}' does not exist.","Try 'mkdir $ENV{'TMPDIR'}'");
::error("Tmpdir '$ENV{'TMPDIR'}' does not exist.","Try 'mkdir ".
Q($ENV{'TMPDIR'})."'");
} else {
::error("Tmpdir '$ENV{'TMPDIR'}' is not writable.","Try 'chmod +w $ENV{'TMPDIR'}'");
::error("Tmpdir '$ENV{'TMPDIR'}' is not writable.","Try 'chmod +w ".
Q($ENV{'TMPDIR'})."'");
}
::wait_and_exit(255);
exit(255);
}
do {
$tmpname = $ENV{'TMPDIR'}."/".$name.
@ -332,6 +335,76 @@ sub Q($) {
}
sub status(@) {
my @w = @_;
my $fh = $Global::status_fd || *STDERR;
print $fh map { ($_, "\n") } @w;
flush $fh;
}
sub status_no_nl(@) {
my @w = @_;
my $fh = $Global::status_fd || *STDERR;
print $fh @w;
flush $fh;
}
sub warning(@) {
my @w = @_;
my $prog = $Global::progname || "parsort";
status_no_nl(map { ($prog, ": Warning: ", $_, "\n"); } @w);
}
{
my %warnings;
sub warning_once(@) {
my @w = @_;
my $prog = $Global::progname || "parsort";
$warnings{@w}++ or
status_no_nl(map { ($prog, ": Warning: ", $_, "\n"); } @w);
}
}
sub error(@) {
my @w = @_;
my $prog = $Global::progname || "parsort";
status(map { ($prog.": Error: ". $_); } @w);
}
sub die_bug($) {
my $bugid = shift;
print STDERR
("$Global::progname: This should not happen. You have found a bug. ",
"Please follow\n",
"https://www.gnu.org/software/parallel/man.html#REPORTING-BUGS\n",
"\n",
"Include this in the report:\n",
"* The version number: $Global::version\n",
"* The bugid: $bugid\n",
"* The command line being run\n",
"* The files being read (put the files on a webserver if they are big)\n",
"\n",
"If you get the error on smaller/fewer files, please include those instead.\n");
exit(255);
}
sub version() {
# Returns: N/A
print join
("\n",
"GNU $Global::progname $Global::version",
"Copyright (C) 2007-2021 Ole Tange, http://ole.tange.dk and Free Software",
"Foundation, Inc.",
"License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>",
"This is free software: you are free to change and redistribute it.",
"GNU $Global::progname comes with no warranty.",
"",
"Web site: https://www.gnu.org/software/${Global::progname}\n",
"When using programs that use GNU Parallel to process data for publication",
"please cite as described in 'parallel --citation'.\n",
);
}
if(@ARGV) {
sort_files(@ARGV);
} elsif(length $opt::files0_from) {

View file

@ -102,6 +102,16 @@ par_dummy() {
# --files0-from=$files0
}
par_tmpdir() {
export TMPDIR="/tmp/parsort dir"
rm -rf "$TMPDIR"
echo Fail: no such dir | parsort
mkdir "$TMPDIR"
echo OK | parsort
chmod -w "$TMPDIR"
echo Fail: writeable | parsort
}
setup
export -f $(compgen -A function | grep par_)