From 42466ac7d8bcd3fd1d1097d3dbf1f77cd1a2daa0 Mon Sep 17 00:00:00 2001 From: Pascal Terjan Date: Sun, 3 Dec 2023 18:31:21 +0000 Subject: iurt: Use the target dir when rebuilding chroot Currently we when building a tmpdir, making a tar of it, deleting it and then untar into the target. --- NEWS | 1 + lib/Iurt/Chroot.pm | 41 ++++++++++++++++------------------------- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/NEWS b/NEWS index e31303d..e76243e 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ machines - iurt: Fix / of the chroot belonging to the user instead of root - iurt: Make generation of the chroot archive more atomic +- iurt: Use the target directory when reference chroot needs to be updated 0.8.2.2 - ulri: Fix a crash after build failures diff --git a/lib/Iurt/Chroot.pm b/lib/Iurt/Chroot.pm index d87a6b9..8a2e04b 100644 --- a/lib/Iurt/Chroot.pm +++ b/lib/Iurt/Chroot.pm @@ -317,53 +317,44 @@ sub create_build_chroot { sub create_build_chroot_tar { my ($chroot, $chroot_tar, $run, $config) = @_; - my $tmp_chroot = mktemp("$chroot.tmp.XXXXXX"); my $rebuild; - my $clean = sub { - plog("Remove temporary chroot"); - sudo($config, '--rm', '-r', $tmp_chroot); - }; plog('NOTIFY', "creating chroot"); - # Create this directory as root as it will be / of the chroot - sudo($config, "--mkdir", "-p", "$tmp_chroot"); if (!-f $chroot_tar) { plog("rebuild chroot tarball"); $rebuild = 1; } elsif (!$run->{fixed_media}) { - plog('DEBUG', "decompressing /var/log/qa from $chroot_tar in $tmp_chroot"); - sudo($config, '--untar', $chroot_tar, $tmp_chroot, "./var/log/qa"); - $rebuild = check_chroot_need_update($tmp_chroot, $run, $config); + my $tmp_chroot = mktemp("$chroot.tmp.XXXXXX"); + sudo($config, "--mkdir", "-p", "$tmp_chroot"); + plog('DEBUG', "decompressing /var/log/qa from $chroot_tar in $tmp_chroot"); + sudo($config, '--untar', $chroot_tar, $tmp_chroot, "./var/log/qa"); + $rebuild = check_chroot_need_update($tmp_chroot, $run, $config); + sudo($config, '--rm', '-r', $tmp_chroot); } + sudo($config, '--rm', '-r', $chroot); + # Create this directory as root as it will be / of the chroot + sudo($config, "--mkdir", "-p", "$chroot"); if ($rebuild) { - sudo($config, '--rm', '-r', $chroot); - if (!build_chroot($run, $config, $tmp_chroot)) { + if (!build_chroot($run, $config, $chroot)) { plog('NOTIFY', "creating chroot failed."); - $clean->(); + sudo($config, '--rm', '-r', $chroot); return; } + plog('NOTIFY', "chroot recreated in $chroot"); my $tmp_tar = mktemp("$chroot_tar.tmp.XXXXXX"); - sudo($config, "--tar", $chroot_tar, $tmp_chroot); + sudo($config, "--tar", $chroot_tar, $chroot); if (rename($tmp_tar, $chroot_tar)) { plog('NOTIFY', "archive creation failed."); unlink($tmp_tar); - $clean->(); return; } - - } - - if (!-d $chroot) { - plog('DEBUG', "recreate chroot $chroot"); - plog('NOTIFY', "recreate chroot"); - sudo($config, "--mkdir", "-p", "$tmp_chroot"); + plog('NOTIFY', "chroot archived in $chroot_tar"); + } else { sudo($config, '--untar', $chroot_tar, $chroot); - plog('NOTIFY', "chroot recreated in $chroot_tar (live in $chroot)"); + plog('NOTIFY', "chroot recreated in $chroot (from $chroot_tar)"); } - - $clean->(); 1; } -- cgit v1.2.1