parallel: changed hex encoding to base64 encoding.

This commit is contained in:
Ole Tange 2015-01-18 06:08:46 +01:00
parent b784f4eca6
commit 29ce26de3f

View file

@ -5039,7 +5039,7 @@ sub cleanup_cmd {
$dir .= $_."/"; $dir .= $_."/";
unshift @rmdir, ::shell_quote_file($dir); unshift @rmdir, ::shell_quote_file($dir);
} }
my $rmdir = @rmdir ? "rmdir @rmdir 2>/dev/null;" : ""; my $rmdir = @rmdir ? "rmdir @rmdir >&/dev/null;" : "";
if(defined $opt::workdir and $opt::workdir eq "...") { if(defined $opt::workdir and $opt::workdir eq "...") {
$rmdir .= "rm -rf " . ::shell_quote_file($workdir).';'; $rmdir .= "rm -rf " . ::shell_quote_file($workdir).';';
} }
@ -5814,6 +5814,7 @@ sub wrapped {
# Exit value: # Exit value:
# empty input = true # empty input = true
# some input = exit val from command # some input = exit val from command
# sh -c needed as csh cannot hide stderr
qq{ sh -c 'dd bs=1 count=1 of=$tmpfile 2>/dev/null'; }. qq{ sh -c 'dd bs=1 count=1 of=$tmpfile 2>/dev/null'; }.
qq{ test \! -s "$tmpfile" && rm -f "$tmpfile" && exec true; }. qq{ test \! -s "$tmpfile" && rm -f "$tmpfile" && exec true; }.
qq{ (cat $tmpfile; rm $tmpfile; cat - ) | }. qq{ (cat $tmpfile; rm $tmpfile; cat - ) | }.
@ -5841,20 +5842,21 @@ sub sshlogin {
return $self->{'sshlogin'}; return $self->{'sshlogin'};
} }
sub string_zip_hex { sub string_zip_base64 {
# Pipe string through 'bzip2 -9' and hex encode it into 1000 byte # Pipe string through 'bzip2 -9' and base64 encode it into 1000
# blocks. # byte blocks.
# 1000 bytes is the largest word size csh supports # 1000 bytes is the largest word size csh supports
# Input: # Input:
# @strings = to be encoded # @strings = to be encoded
# Returns: # Returns:
# @hex = 1000 byte block # @base64 = 1000 byte block
my($zipin_fh, $zipout_fh,@hex); my($zipin_fh, $zipout_fh,@base64);
::open3($zipin_fh,$zipout_fh,">&STDERR","bzip2 -9"); ::open3($zipin_fh,$zipout_fh,">&STDERR","bzip2 -9");
if(fork) { if(fork) {
close $zipin_fh; close $zipin_fh;
# Chop hex into 1000 byte blocks $Global::use{"MIME::Base64"} ||= eval "use MIME::Base64; 1;";
@hex = unpack("(H1000)*",join"",<$zipout_fh>); # Split base64 encoded into 1000 byte blocks
@base64 = unpack("(A1000)*",encode_base64((join"",<$zipout_fh>),""));
close $zipout_fh; close $zipout_fh;
} else { } else {
close $zipout_fh; close $zipout_fh;
@ -5862,22 +5864,22 @@ sub string_zip_hex {
close $zipin_fh; close $zipin_fh;
exit; exit;
} }
::debug("hex","Orig:@_\nAs hex:@hex\n"); ::debug("base64","Orig:@_\nAs base64:@base64\n");
return @hex; return @base64;
} }
sub hex_zip_eval { sub base64_zip_eval {
# Script that: # Script that:
# * reads hexstrings from @ARGV # * reads base64 strings from @ARGV
# * unhexes them # * decodes them
# * pipes through 'bzip2 -dc' # * pipes through 'bzip2 -dc'
# * evals the result # * evals the result
# Reverse of string_bz_hex + eval # Reverse of string_zip_base64 + eval
# Will be wrapped in ' so single quote is forbidden # Will be wrapped in ' so single quote is forbidden
# Returns: # Returns:
# $script = 1-liner for perl -e # $script = 1-liner for perl -e
my $script = ::spacefree(0,q{ my $script = ::spacefree(0,q{
@GNU_Parallel=("use","IPC::Open3;"); @GNU_Parallel=("use","IPC::Open3;","use","MIME::Base64");
eval "@GNU_Parallel"; eval "@GNU_Parallel";
$SIG{CHLD}="IGNORE"; $SIG{CHLD}="IGNORE";
@ -5892,18 +5894,19 @@ sub hex_zip_eval {
close $out; close $out;
} else { } else {
close $out; close $out;
# Pipe decoded hex into 'bzip2 -dc' # Pipe decoded base64 into 'bzip2 -dc'
print $in (pack("H*",join"",@ARGV)); print $in (decode_base64(join"",@ARGV));
close $in; close $in;
exit; exit;
} }
wait; wait;
eval $eval; eval $eval;
}); });
::debug("hex",$script,"\n"); ::debug("base64",$script,"\n");
return $script; return $script;
} }
sub sshlogin_wrap { sub sshlogin_wrap {
# Wrap the command with the commands needed to run remotely # Wrap the command with the commands needed to run remotely
# Input: # Input:
@ -6013,7 +6016,7 @@ sub sshlogin_wrap {
if($ENV{"parallel_bash_environment"}) { if($ENV{"parallel_bash_environment"}) {
$bashfuncset .= '$bashfunc .= "eval\ \"\$parallel_bash_environment\"\;";'; $bashfuncset .= '$bashfunc .= "eval\ \"\$parallel_bash_environment\"\;";';
} }
::debug("hex",$envset,$bashfuncset,"\n"); ::debug("base64",$envset,$bashfuncset,"\n");
return $csh_friendly,$envset,$bashfuncset; return $csh_friendly,$envset,$bashfuncset;
} }
@ -6062,8 +6065,8 @@ sub sshlogin_wrap {
$command =~ "\n") { $command =~ "\n") {
# csh does not deal well with > 1000 chars in one word # csh does not deal well with > 1000 chars in one word
# csh does not deal well with $ENV with \n # csh does not deal well with $ENV with \n
$quoted_remote_command = "exec perl -e '".::shell_quote_scalar(hex_zip_eval())."' ". $quoted_remote_command = "exec perl -e '".::shell_quote_scalar(base64_zip_eval())."' ".
join" ",string_zip_hex($remote_command); join" ",string_zip_base64($remote_command);
} }
$self->{'sshlogin_wrap'} = $self->{'sshlogin_wrap'} =
($pre ($pre