From ae71b49f6939ef10189d1b38e1579d8fcc8ac698 Mon Sep 17 00:00:00 2001
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
Date: Thu, 2 Dec 2021 13:15:47 +0100
Subject: [PATCH] split out writing (host-side) pacman.conf

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
 PVE/AAB.pm | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/PVE/AAB.pm b/PVE/AAB.pm
index 2de341c..ccac7f2 100644
--- a/PVE/AAB.pm
+++ b/PVE/AAB.pm
@@ -231,17 +231,27 @@ sub initialize {
 	die "no sources/mirrors specified";
     }
 
+    $self->write_pacman_conf();
+
+    $self->logmsg("configured VE $self->{veid}\n");
+}
+
+sub write_pacman_conf {
+    my ($self) = @_;
+
+    my $config = $self->{config};
+
     $config->{source} //= [];
     $config->{mirror} //= [];
 
-    my $servers = "Server = "
-                . join("\nServer = ", @{$config->{source}}, @{$config->{mirror}})
-                . "\n";
+    my $servers = "Server = ".join("\nServer = ", @{$config->{source}}, @{$config->{mirror}}) ."\n";
+
+    my $fh = IO::File->new($self->{'pacman.conf'}, O_WRONLY | O_CREAT | O_EXCL)
+        or die "unable to write pacman config file $self->{'pacman.conf'} - $!";
 
-    $fh = IO::File->new($self->{'pacman.conf'}, O_WRONLY|O_CREAT|O_EXCL) ||
-	die "unable to write pacman config file $self->{'pacman.conf'} - $!";
     my $arch = $config->{architecture};
     $arch = 'x86_64' if $arch eq 'amd64';
+
     print $fh <<"EOF";
 [options]
 HoldPkg = pacman glibc
@@ -257,11 +267,9 @@ $servers
 $servers
 EOF
 
-    if ($config->{architecture} eq 'x86_64') {
-	print $fh "[multilib]\n$servers\n";
-    }
+    print $fh "[multilib]\n$servers\n" if $config->{architecture} eq 'x86_64';
 
-    $self->logmsg("configured VE $self->{veid}\n");
+    close($fh);
 }
 
 sub ve_status {