mirror of https://github.com/digint/btrbk
btrbk: tidy assemble piped command; remove dead code
parent
af6d719acc
commit
47a3aa5849
37
btrbk
37
btrbk
|
@ -743,36 +743,23 @@ sub decompress_cmd_text($)
|
||||||
return compress_cmd_text($_[0], 1);
|
return compress_cmd_text($_[0], 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub _assemble_cmd($;$)
|
sub _piped_cmd_txt($)
|
||||||
{
|
{
|
||||||
my $cmd_pipe = shift;
|
my $cmd_pipe = shift;
|
||||||
my $catch_stderr = shift;
|
|
||||||
my $cmd = "";
|
my $cmd = "";
|
||||||
|
|
||||||
# simple single-command
|
|
||||||
if(scalar(@$cmd_pipe) == 1) {
|
|
||||||
$cmd = $cmd_pipe->[0]->{cmd_text};
|
|
||||||
$cmd .= ' 2>&1' if($catch_stderr && $cmd_pipe->[0]->{catch_stderr});
|
|
||||||
return $cmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
# cmd result is something like this:
|
|
||||||
# { btrfs send <src> 2>&3 | mbuffer | btrfs receive <dst> 2>&3 ; } 3>&1
|
|
||||||
my $pipe = "";
|
my $pipe = "";
|
||||||
$cmd = "{ " if($catch_stderr);
|
my $last;
|
||||||
foreach (@$cmd_pipe) {
|
foreach (map $_->{cmd_text}, @$cmd_pipe) {
|
||||||
if($_->{cmd_text} =~ /^>/) {
|
die if($last);
|
||||||
|
if(/^>/) {
|
||||||
|
# can't be first, must be last
|
||||||
die unless($pipe);
|
die unless($pipe);
|
||||||
$cmd .= ' ' . $_->{cmd_text};
|
$last = 1;
|
||||||
$pipe = undef; # this dies if it is not last command
|
$pipe = ' ';
|
||||||
} else {
|
}
|
||||||
$cmd .= $pipe . $_->{cmd_text};
|
$cmd .= $pipe . $_;
|
||||||
$cmd .= ' 2>&3' if($catch_stderr && $_->{catch_stderr});
|
|
||||||
$pipe = ' | ';
|
$pipe = ' | ';
|
||||||
}
|
}
|
||||||
}
|
|
||||||
$cmd .= ' ; } 3>&1' if($catch_stderr);
|
|
||||||
|
|
||||||
return $cmd;
|
return $cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -903,7 +890,7 @@ sub run_cmd(@)
|
||||||
|
|
||||||
my $rsh_text = _safe_cmd($href->{rsh}, \@unsafe_cmd);
|
my $rsh_text = _safe_cmd($href->{rsh}, \@unsafe_cmd);
|
||||||
return undef unless(defined($rsh_text));
|
return undef unless(defined($rsh_text));
|
||||||
$href->{cmd_text} = $rsh_text . " '" . _assemble_cmd(\@rsh_cmd_pipe) . "'";
|
$href->{cmd_text} = $rsh_text . " '" . _piped_cmd_txt(\@rsh_cmd_pipe) . "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
# local stream_buffer, rate_limit and show_progress in front of stream sink
|
# local stream_buffer, rate_limit and show_progress in front of stream sink
|
||||||
|
@ -917,7 +904,7 @@ sub run_cmd(@)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
my $cmd = _assemble_cmd(\@cmd_pipe);
|
my $cmd = _piped_cmd_txt(\@cmd_pipe);
|
||||||
|
|
||||||
if(scalar(@unsafe_cmd)) {
|
if(scalar(@unsafe_cmd)) {
|
||||||
ERROR "Unsafe command `$cmd` (offending string: " . join(', ', @unsafe_cmd) . ')';
|
ERROR "Unsafe command `$cmd` (offending string: " . join(', ', @unsafe_cmd) . ')';
|
||||||
|
|
Loading…
Reference in New Issue