]> git.proxmox.com Git - pve-storage.git/commitdiff
prune backups: make vmid filtering more robust
authorFabian Ebner <f.ebner@proxmox.com>
Wed, 7 Apr 2021 10:25:37 +0000 (12:25 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 9 Apr 2021 10:41:34 +0000 (12:41 +0200)
by relying on archive_info's vmid first. archive_info is already used to
determine if it's a standard name, and in that case the vmid is certainly set.

Also add asserts to make sure we got what we expected.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
PVE/Storage/Plugin.pm

index 05f1701c5ef0cf393f48819c91bc62fb6da68bec..07eb88f0145f963cacc4306293844c6e28f4b945 100644 (file)
@@ -1233,9 +1233,9 @@ sub prune_backups {
 
     foreach my $backup (@{$backups}) {
        my $volid = $backup->{volid};
-       my $backup_vmid = $backup->{vmid};
        my $archive_info = eval { PVE::Storage::archive_info($volid) } // {};
        my $backup_type = $archive_info->{type} // 'unknown';
+       my $backup_vmid = $archive_info->{vmid} // $backup->{vmid};
 
        next if defined($type) && $type ne $backup_type;
 
@@ -1248,6 +1248,9 @@ sub prune_backups {
        $prune_entry->{vmid} = $backup_vmid if defined($backup_vmid);
 
        if ($archive_info->{is_std_name}) {
+           die "internal error - got no vmid\n" if !defined($backup_vmid);
+           die "internal error - got wrong vmid\n" if defined($vmid) && $backup_vmid ne $vmid;
+
            $prune_entry->{ctime} = $archive_info->{ctime};
            my $group = "$backup_type/$backup_vmid";
            push @{$backup_groups->{$group}}, $prune_entry;