install-grub.pl: Write state file atomically.
Other files were already written atomically, but not this one.
This commit is contained in:
parent
0dcad215fe
commit
81c15742ce
1 changed files with 8 additions and 1 deletions
|
@ -682,11 +682,18 @@ if (($requireNewInstall != 0) && ($efiTarget eq "only" || $efiTarget eq "both"))
|
||||||
|
|
||||||
# update GRUB state file
|
# update GRUB state file
|
||||||
if ($requireNewInstall != 0) {
|
if ($requireNewInstall != 0) {
|
||||||
open FILE, ">$bootPath/grub/state" or die "cannot create $bootPath/grub/state: $!\n";
|
# Temp file for atomic rename.
|
||||||
|
my $stateFile = "$bootPath/grub/state";
|
||||||
|
my $stateFileTmp = $stateFile . ".tmp";
|
||||||
|
|
||||||
|
open FILE, ">$stateFileTmp" or die "cannot create $stateFileTmp: $!\n";
|
||||||
print FILE get("fullName"), "\n" or die;
|
print FILE get("fullName"), "\n" or die;
|
||||||
print FILE get("fullVersion"), "\n" or die;
|
print FILE get("fullVersion"), "\n" or die;
|
||||||
print FILE $efiTarget, "\n" or die;
|
print FILE $efiTarget, "\n" or die;
|
||||||
print FILE join( ",", @deviceTargets ), "\n" or die;
|
print FILE join( ",", @deviceTargets ), "\n" or die;
|
||||||
print FILE $efiSysMountPoint, "\n" or die;
|
print FILE $efiSysMountPoint, "\n" or die;
|
||||||
close FILE or die;
|
close FILE or die;
|
||||||
|
|
||||||
|
# Atomically switch to the new state file
|
||||||
|
rename $stateFileTmp, $stateFile or die "cannot rename $stateFileTmp to $stateFile\n";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue