mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-21 01:42:15 +00:00
fix(genimage): restore boot files from the recorded backups
publish_staged_boot_files looked for the backup of a file during the rollback to decide whether to restore it or remove the published file. When that lookup failed, it removed the published file, and the staging cleanup then removed the backup. publish_staged_boot_files now records each backup that it makes and rolls back from that record. A file without an earlier copy is one for which link reports ENOENT. Any other link error stops the publication.
This commit is contained in:
@@ -155,11 +155,14 @@ sub pack_initrd {
|
||||
sub publish_staged_boot_files {
|
||||
my ($native_bootdir, $destdir, @modes) = @_;
|
||||
my @files = ([ 'kernel', 'kernel' ], map { [ "initrd-$_.gz", "initial ramdisk for $_" ] } @modes);
|
||||
my %backup;
|
||||
foreach my $file (@files) {
|
||||
my ($name, $what) = @$file;
|
||||
next unless -e "$destdir/$name" || -l "$destdir/$name";
|
||||
link("$destdir/$name", "$native_bootdir/previous-$name")
|
||||
or die("Error: failed to preserve the previous $what: $!\n");
|
||||
if (link("$destdir/$name", "$native_bootdir/previous-$name")) {
|
||||
$backup{$name} = 1;
|
||||
} elsif (!$!{ENOENT}) {
|
||||
die("Error: failed to preserve the previous $what: $!\n");
|
||||
}
|
||||
}
|
||||
my @published;
|
||||
foreach my $file (@files) {
|
||||
@@ -174,9 +177,8 @@ sub publish_staged_boot_files {
|
||||
my @failed;
|
||||
foreach my $done (@attempted, reverse @published) {
|
||||
my ($done_name, $done_what) = @$done;
|
||||
my $previous = "$native_bootdir/previous-$done_name";
|
||||
my $restored = (-e $previous || -l $previous)
|
||||
? rename($previous, "$destdir/$done_name")
|
||||
my $restored = $backup{$done_name}
|
||||
? rename("$native_bootdir/previous-$done_name", "$destdir/$done_name")
|
||||
: unlink("$destdir/$done_name");
|
||||
push @failed, "$done_what rollback failed: $!" unless $restored;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user