[pve-devel] [PATCH v2 container] use PVE::Storage::extract_vzdump_config_tar

Fabian Grünbichler f.gruenbichler at proxmox.com
Fri Jun 3 11:09:19 CEST 2016


which is based on the former tar_archive_search_conf code
---
Note: requires vzdump config extraction patch series

Changes in v2:
- us qr operator to pass regexp

 src/PVE/LXC/Create.pm | 37 +------------------------------------
 1 file changed, 1 insertion(+), 36 deletions(-)

diff --git a/src/PVE/LXC/Create.pm b/src/PVE/LXC/Create.pm
index 222551d..98a799f 100644
--- a/src/PVE/LXC/Create.pm
+++ b/src/PVE/LXC/Create.pm
@@ -67,45 +67,10 @@ sub restore_archive {
     });
 }
 
-sub tar_archive_search_conf {
-    my ($archive) = @_;
-
-    die "ERROR: file '$archive' does not exist\n" if ! -f $archive;
-
-    my $pid = open(my $fh, '-|', 'tar', 'tf', $archive) ||
-       die "unable to open file '$archive'\n";
-
-    my $file;
-    while (defined($file = <$fh>)) {
-	if ($file =~ m!^(\./etc/vzdump/(pct|vps)\.conf)$!) {
-	    $file = $1; # untaint
-	    last;
-	}
-    }
-
-    kill 15, $pid;
-    waitpid $pid, 0;
-    close $fh;
-
-    die "ERROR: archive contains no configuration file\n" if !$file;
-    chomp $file;
-
-    return $file;
-}
-
 sub recover_config {
     my ($archive) = @_;
 
-    my $conf_file = tar_archive_search_conf($archive);
-    
-    my $raw = '';
-    my $out = sub {
-	my $output = shift;
-	$raw .= "$output\n";
-    };
-
-    PVE::Tools::run_command(['tar', '-xpOf', $archive, $conf_file, '--occurrence'], outfunc => $out);
-
+    my ($raw, $conf_file) = PVE::Storage::extract_vzdump_config_tar($archive, qr!(\./etc/vzdump/(pct|vps)\.conf)$!);
     my $conf;
     my $mp_param = {};
 
-- 
2.1.4




More information about the pve-devel mailing list