From 2852939aa586d0a4c850481f84c7516fa6a9f379 Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Sun, 3 Nov 2013 04:22:48 +0100 Subject: [PATCH] parallel: --compress now works with --files and --results. --- src/parallel | 51 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/parallel b/src/parallel index cb34ac2b..76c5a864 100755 --- a/src/parallel +++ b/src/parallel @@ -798,7 +798,7 @@ sub get_options_from_array { sub parse_options { # Returns: N/A # Defaults: - $Global::version = 20131022; + $Global::version = 20131102; $Global::progname = 'parallel'; $Global::infinity = 2**31; $Global::debug = 0; @@ -2811,12 +2811,13 @@ sub loadavg { # If the currently know loadavg is too old: # Recompute a new one in the background # Returns: - # last load average computed + # $last_loadavg = last load average computed (undef if none) my $self = shift; # Should we update the loadavg file? my $update_loadavg_file = 0; if(-r $self->{'loadavg_file'}) { - open(my $load_fh, "<", $self->{'loadavg_file'}) || ::die_bug("loadavg_file-r"); + open(my $load_fh, "<", $self->{'loadavg_file'}) || + ::die_bug("loadavg_file-r: ".$self->{'loadavg_file'}); local $/ = undef; my $load_out = <$load_fh>; close $load_fh; @@ -3919,7 +3920,7 @@ sub openoutputfiles { # Open files for STDOUT and STDERR # Set file handles in $self->fd and possibly $self->fd_input my $self = shift; - my ($outfh, $errfh, $outname, $errname); + my ($outfh, $errfh, $outname, $errname, $unlink_out, $unlink_err); if($opt::results) { my $args_as_dirname = $self->{'commandline'}->args_as_dirname(); # prefix/name1/val1/name2/val2/ @@ -3940,29 +3941,18 @@ sub openoutputfiles { } elsif($Global::grouped) { # To group we create temporary files for STDOUT and STDERR # To avoid the cleanup unlink the files immediately (but keep them open) - if($opt::compress) { - my($i_outfh,$i_errfh); - ($i_outfh, $outname) = ::tempfile(SUFFIX => ".par"); - ($i_errfh, $errname) = ::tempfile(SUFFIX => ".par"); - $self->set_fd_input(1, $i_outfh); - $self->set_fd_input(2, $i_errfh); - my $rm = $Global::debug ? "true" : "rm"; - ::debug("| ($rm $outname; $opt::compress_program) > $outname\n"); - open($outfh,"|-","($rm $outname; $opt::compress_program) > $outname") || die $?; - ::debug("| ($rm $errname; $opt::compress_program) > $errname\n"); - open($errfh,"|-","($rm $errname; $opt::compress_program) > $errname") || die $?; - } elsif(@Global::tee_jobs) { + if(@Global::tee_jobs) { # files must be removed when the tee is done } elsif($opt::files) { ($outfh, $outname) = ::tempfile(SUFFIX => ".par"); ($errfh, $errname) = ::tempfile(SUFFIX => ".par"); # --files => only remove stderr - unlink $errname; + $unlink_err = 1; } else { ($outfh, $outname) = ::tempfile(SUFFIX => ".par"); ($errfh, $errname) = ::tempfile(SUFFIX => ".par"); - unlink $outname; - unlink $errname; + $unlink_out = 1; + $unlink_err = 1; } } else { # --ungroup @@ -3971,11 +3961,28 @@ sub openoutputfiles { # File name must be empty as it will otherwise be printed $outname = ""; $errname = ""; + $unlink_out = 1; + $unlink_err = 1; } $self->set_fd_file_name(1,$outname); $self->set_fd_file_name(2,$errname); - $self->set_fd(1,$outfh); - $self->set_fd(2,$errfh); + if($opt::compress) { + $self->set_fd_input(1, $outfh); + $self->set_fd_input(2, $errfh); + my $rm = $unlink_out ? "rm" : "true"; + ::debug("| ($rm $outname; $opt::compress_program) > $outname\n"); + open(my $coutfh,"|-","($rm $outname; $opt::compress_program) > $outname") || die $?; + $rm = $unlink_err ? "rm" : "true"; + ::debug("| ($rm $errname; $opt::compress_program) > $errname\n"); + open(my $cerrfh,"|-","($rm $errname; $opt::compress_program) > $errname") || die $?; + $self->set_fd(1,$coutfh); + $self->set_fd(2,$cerrfh); + } else { + $self->set_fd(1,$outfh); + $self->set_fd(2,$errfh); + $unlink_out && unlink($outname); + $unlink_err && unlink($errname); + } } sub set_fd { @@ -4754,6 +4761,8 @@ sub print { } ::debug("File descriptor $fdno:"); if($opt::files) { + # If --compress: $in_fd must be closed first. + close($in_fd); if($fdno == 1 and $self->fd_file_name($fdno)) { print $out_fd $self->fd_file_name($fdno),"\n"; }