diff options
Diffstat (limited to 'lib/Iurt/Chroot.pm')
-rw-r--r-- | lib/Iurt/Chroot.pm | 41 |
1 files changed, 16 insertions, 25 deletions
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; } |