From 8a059f4665fe9e87db23cb5540368346c831ade7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 6 Nov 2026 15:25:36 -0300 Subject: [PATCH] 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. --- .../share/xcat/netboot/imgutils/imgutils.pm | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm index 653a0b8254..ba612c6dec 100644 --- a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm +++ b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm @@ -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; }