[pve-devel] [PATCH access-control] add ls command for pvum user

Dietmar Maurer dietmar at proxmox.com
Wed May 9 08:56:57 CEST 2018


I am unable to apply this patch:

Applying: add ls command for pvum user
error: patch failed: PVE/CLI/pveum.pm:37
error: PVE/CLI/pveum.pm: patch does not apply
Patch failed at 0001 add ls command for pvum user

more comments inline:

> On May 8, 2018 at 5:25 PM Stoiko Ivanov <s.ivanov at proxmox.com> wrote:
> 
> 
> fixes #1502
> 
> ---
>  PVE/CLI/pveum.pm | 60
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 60 insertions(+)
> 
> diff --git a/PVE/CLI/pveum.pm b/PVE/CLI/pveum.pm
> index a4e584d..107b759 100755
> --- a/PVE/CLI/pveum.pm
> +++ b/PVE/CLI/pveum.pm
> @@ -18,6 +18,7 @@ use PVE::API2::ACL;
>  use PVE::API2::AccessControl;
>  use PVE::JSONSchema qw(get_standard_option);
>  use PVE::CLIHandler;
> +use List::Util qw(reduce);
>  
>  use base qw(PVE::CLIHandler);
>  
> @@ -37,25 +38,84 @@ sub read_password {
>      return $input;
>  }
>  
> +sub print_index {
> +    my ($formatopts, $data) = @_;
> +    my ($formatstring, @keylist, @titles, %defaults);
> +    @keylist = map { $_->{'key'} } @$formatopts;
> +    foreach my $col ( @$formatopts ) {
> +	my ($key, $title, $cutoff) = @$col{ qw(key name cutoff) };
> +	$title = $key if !defined $title;
> +	$defaults{$key} = $col->{'default'};
> +	push @titles, ($title);
> +	my $titlelen = length $title;
> +	my @value_lengths = map { length($_->{$key}) // 1 } @$data;
> +	my $longest = reduce { $a > $b ? $a : $b  } @value_lengths;

This is incredible complex and wasteful code. I suggest to use something like:

my $longest = 0;
foreach my $entry (@$data) {
  my $length = length($entry->{$key});
  $longest = $length if $length > $longest;
}

No need to use List::Utils ...



More information about the pve-devel mailing list