[pve-devel] [PATCH common 02/10] PBSClient: allow running other binaries

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Apr 21 16:29:19 CEST 2021


On 21.04.21 13:15, Stefan Reiter wrote:
> ...such as proxmox-file-restore.
> 

For public interface I'd rather see a separate sub, like:

run_file_restore_cmd

and ideally not even that would be required from an external POV, i.e., why want
to avoid to expose a general run_something command here, a clear interface, like
you add then for most (all?) things like file_restore_extract, file_restore_list,
..., is in general better (when thinking anti-spaghetti-no-check code).

> Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
> ---
> 
> Fixes indentation where "binary =>" is added.
> 
>  src/PVE/PBSClient.pm | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/src/PVE/PBSClient.pm b/src/PVE/PBSClient.pm
> index f05471c..857cff0 100644
> --- a/src/PVE/PBSClient.pm
> +++ b/src/PVE/PBSClient.pm
> @@ -139,8 +139,9 @@ my sub do_raw_client_cmd {
>  
>      my $use_crypto = $USE_CRYPT_PARAMS->{$client_cmd};
>  
> -    my $client_exe = '/usr/bin/proxmox-backup-client';
> -    die "executable not found '$client_exe'! Proxmox backup client not installed?\n"
> +    my $client_exe = (delete $opts{binary}) || 'proxmox-backup-client';
> +    $client_exe = "/usr/bin/$client_exe";
> +    die "executable not found '$client_exe'! Proxmox backup client or file restore not installed?\n"
>  	if ! -x $client_exe;
>  
>      my $scfg = $self->{scfg};
> @@ -193,22 +194,25 @@ my sub run_raw_client_cmd {
>  }
>  
>  my sub run_client_cmd {
> -    my ($self, $client_cmd, $param, $no_output) = @_;
> +    my ($self, $client_cmd, $param, $no_output, $binary) = @_;
>  
>      my $json_str = '';
>      my $outfunc = sub { $json_str .= "$_[0]\n" };
>  
> +    $binary //= 'proxmox-backup-client';
> +
>      $param = [] if !defined($param);
>      $param = [ $param ] if !ref($param);
>  
>      $param = [@$param, '--output-format=json'] if !$no_output;
>  
>      do_raw_client_cmd(
> -        $self,
> -        $client_cmd,
> -        $param,
> -        outfunc => $outfunc,
> -        errmsg => 'proxmox-backup-client failed'
> +	$self,
> +	$client_cmd,
> +	$param,
> +	outfunc => $outfunc,
> +	errmsg => "$binary failed",
> +	binary => $binary,
>      );
>  
>      return undef if $no_output;
> 






More information about the pve-devel mailing list