[pve-devel] [PATCH v3 storage 02/13] Extend archive_info to include filename and logfilename
Fabian Ebner
f.ebner at proxmox.com
Tue Jun 30 10:24:18 CEST 2020
Only expect the logfilename if the archive has a standard name.
This also gives a mechanism to get an untainted filename.
archive_info can take either a volume ID or a path as it's
currently implemented. This is useful for vzdump when there
is no storage (i.e. for 'vzdump --dumpdir'). Add a test case for this.
Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
PVE/Storage.pm | 13 ++++++++-----
test/archive_info_test.pm | 22 ++++++++++++++++++++++
2 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index 07a4f53..ac0dccd 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -1395,15 +1395,18 @@ sub archive_info {
my $info;
my $volid = basename($archive);
- if ($volid =~ /^vzdump-(lxc|openvz|qemu)-\d+-.+\.(tgz$|tar|vma)(?:\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?$/) {
- my ($type, $format, $comp) = ($1, $2, $3);
+ if ($volid =~ /^(vzdump-(lxc|openvz|qemu)-\d+-.+\.(tgz$|tar|vma)(?:\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?)$/) {
+ my $filename = "$1"; # untaint
+ my ($type, $format, $comp) = ($2, $3, $4);
my $format_re = defined($comp) ? "$format.$comp" : "$format";
$info = decompressor_info($format, $comp);
+ $info->{filename} = $filename;
$info->{type} = $type;
- if ($volid =~ /^vzdump-${type}-([1-9][0-9]{2,8})-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.${format_re}$/) {
- $info->{vmid} = int($1);
- $info->{ctime} = timelocal($7, $6, $5, $4, $3 - 1, $2 - 1900);
+ if ($volid =~ /^(vzdump-${type}-([1-9][0-9]{2,8})-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2}))\.${format_re}$/) {
+ $info->{logfilename} = "$1.log";
+ $info->{vmid} = int($2);
+ $info->{ctime} = timelocal($8, $7, $6, $5, $4 - 1, $3 - 1900);
$info->{is_std_name} = 1;
} else {
$info->{is_std_name} = 0;
diff --git a/test/archive_info_test.pm b/test/archive_info_test.pm
index 5e5ca8a..2f9811c 100644
--- a/test/archive_info_test.pm
+++ b/test/archive_info_test.pm
@@ -22,6 +22,8 @@ my $tests = [
description => 'Backup archive, lxc, tgz',
archive => "backup/vzdump-lxc-$vmid-2020_03_30-21_39_30.tgz",
expected => {
+ 'filename' => "vzdump-lxc-$vmid-2020_03_30-21_39_30.tgz",
+ 'logfilename' => "vzdump-lxc-$vmid-2020_03_30-21_39_30.log",
'type' => 'lxc',
'format' => 'tar',
'decompressor' => ['tar', '-z'],
@@ -35,6 +37,8 @@ my $tests = [
description => 'Backup archive, openvz, tgz',
archive => "backup/vzdump-openvz-$vmid-2020_03_30-21_39_30.tgz",
expected => {
+ 'filename' => "vzdump-openvz-$vmid-2020_03_30-21_39_30.tgz",
+ 'logfilename' => "vzdump-openvz-$vmid-2020_03_30-21_39_30.log",
'type' => 'openvz',
'format' => 'tar',
'decompressor' => ['tar', '-z'],
@@ -44,10 +48,26 @@ my $tests = [
'is_std_name' => 1,
},
},
+ {
+ description => 'Backup archive, custom dump directory, qemu, tgz',
+ archive => "/here/be/Back-ups/vzdump-qemu-$vmid-2020_03_30-21_39_30.tgz",
+ expected => {
+ 'filename' => "vzdump-qemu-$vmid-2020_03_30-21_39_30.tgz",
+ 'logfilename' => "vzdump-qemu-$vmid-2020_03_30-21_39_30.log",
+ 'type' => 'qemu',
+ 'format' => 'tar',
+ 'decompressor' => ['tar', '-z'],
+ 'compression' => 'gz',
+ 'vmid' => $vmid,
+ 'ctime' => 1585604370,
+ 'is_std_name' => 1,
+ },
+ },
{
description => 'Backup archive, none, tgz',
archive => "backup/vzdump-qemu-$vmid-whatever-the-name_is_here.tgz",
expected => {
+ 'filename' => "vzdump-qemu-$vmid-whatever-the-name_is_here.tgz",
'type' => 'qemu',
'format' => 'tar',
'decompressor' => ['tar', '-z'],
@@ -86,6 +106,8 @@ for my $virt (sort keys %$bkp_suffix) {
description => "Backup archive, $virt, $format.$suffix",
archive => "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$format.$suffix",
expected => {
+ 'filename' => "vzdump-$virt-$vmid-2020_03_30-21_12_40.$format.$suffix",
+ 'logfilename' => "vzdump-$virt-$vmid-2020_03_30-21_12_40.log",
'type' => "$virt",
'format' => "$format",
'decompressor' => $decomp->{$suffix},
--
2.20.1
More information about the pve-devel
mailing list