[pve-devel] applied: [PATCH guest-common 1/3] reformat code for snapshot tree into GuestHelpers

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Oct 1 17:25:43 CEST 2019


On 10/1/19 9:32 AM, Oguz Bektas wrote:
> qm/pct listsnapshot lack feature parity w.r.t. showing snapshots in a
> tree ordered by the date. by moving this code into GuestHelpers, it can
> be shared.
> 
> Signed-off-by: Oguz Bektas <o.bektas at proxmox.com>
> ---
>  PVE/GuestHelpers.pm | 54 +++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 54 insertions(+)
> 

Applied with a followup (see below). I'll refrain from applying the qemu-server
and container one, as this requires a versioned dependency bump, which your
pending changes do also - I'd rather do one only ;)

Also a v2 to match the followup method name change would be required too,
but no pressure here. 

----8<----
commit 5ee5f8873ea494339fe7251b0a3e46d99d931c81 (HEAD -> master)
Author: Thomas Lamprecht <t.lamprecht at proxmox.com>
Date:   Tue Oct 1 17:20:21 2019 +0200

    followup: rename to print_snapshot_tree, add comment and rename $res param
    
    This was taken from a CLI helper, there $res is a common parameter
    name which denotes that it's the res from the API call the CLI
    command bases on. But here that makes no sense and is not really
    telling about what the value(s) of $res could be. Further explain
    that with a comment.
    
    As this also prints uncoditionally to STDOUT let's say so through the
    method name.
    
    Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>

diff --git a/PVE/GuestHelpers.pm b/PVE/GuestHelpers.pm
index 64e26c9..35059e6 100644
--- a/PVE/GuestHelpers.pm
+++ b/PVE/GuestHelpers.pm
@@ -62,13 +62,15 @@ sub exec_hookscript {
     }
 }
 
-sub snapshot_tree {
-    my ($res) = @_;
+# takes a snapshot list (e.g., qm/pct snapshot_list API call result) and
+# prints it out in a nice tree sorted by age. Can cope with multiple roots
+sub print_snapshot_tree {
+    my ($snapshot_list) = @_;
 
-    my $snapshots = { map { $_->{name} => $_ } @$res };
+    my $snapshots = { map { $_->{name} => $_ } @$snapshot_list };
 
     my @roots;
-    foreach my $e (@$res) {
+    foreach my $e (@$snapshot_list) {
        my $parent;
        if (($parent = $e->{parent}) && defined $snapshots->{$parent}) {
            push @{$snapshots->{$parent}->{children}}, $e->{name};
--




More information about the pve-devel mailing list