lol

grub modernize (#374844)

authored by

Jörg Thalheim and committed by
GitHub
5be6db6b 1d182bfc

+23 -22
+23 -22
nixos/modules/system/boot/loader/grub/install-grub.pl
··· 3 3 use Class::Struct; 4 4 use XML::LibXML; 5 5 use File::Basename; 6 - use File::Path; 6 + use File::Path qw(make_path); 7 7 use File::stat; 8 8 use File::Copy; 9 9 use File::Copy::Recursive qw(rcopy pathrm); ··· 37 37 my ($fn) = @_; 38 38 # enable slurp mode: read entire file in one go 39 39 local $/ = undef; 40 - open my $fh, "<$fn" or return undef; 40 + open my $fh, "<", $fn 41 + or return; 41 42 my $s = <$fh>; 42 43 close $fh; 43 44 # disable slurp mode ··· 48 49 49 50 sub writeFile { 50 51 my ($fn, $s) = @_; 51 - open my $fh, ">$fn" or die "cannot create $fn: $!\n"; 52 + open my $fh, ">", $fn or die "cannot create $fn: $!\n"; 52 53 print $fh $s or die "cannot write to $fn: $!\n"; 53 54 close $fh or die "cannot close $fn: $!\n"; 54 55 } ··· 98 99 99 100 print STDERR "updating GRUB 2 menu...\n"; 100 101 101 - mkpath("$bootPath/grub", 0, 0700); 102 + make_path("$bootPath/grub", { mode => 0700 }); 102 103 103 104 # Discover whether the bootPath is on the same filesystem as / and 104 105 # /nix/store. If not, then all kernels and initrds must be copied to ··· 438 439 $conf .= "\n"; 439 440 440 441 my %copied; 441 - mkpath("$bootPath/kernels", 0, 0755) if $copyKernels; 442 + make_path("$bootPath/kernels", { mode => 0755 }) if $copyKernels; 442 443 443 444 sub copyToKernelsDir { 444 445 my ($path) = @_; ··· 471 472 my $systemName = basename(Cwd::abs_path("$path")); 472 473 my $initrdSecretsPath = "$bootPath/kernels/$systemName-secrets"; 473 474 474 - mkpath(dirname($initrdSecretsPath), 0, 0755); 475 + make_path(dirname($initrdSecretsPath), { mode => 0755 }); 475 476 my $oldUmask = umask; 476 477 # Make sure initrd is not world readable (won't work if /boot is FAT) 477 478 umask 0137; ··· 690 691 # because it is read line-by-line. 691 692 sub readGrubState { 692 693 my $defaultGrubState = GrubState->new(name => "", version => "", efi => "", devices => "", efiMountPoint => "", extraGrubInstallArgs => () ); 693 - open FILE, "<$bootPath/grub/state" or return $defaultGrubState; 694 + open my $fh, "<", "$bootPath/grub/state" or return $defaultGrubState; 694 695 local $/ = "\n"; 695 - my $name = <FILE>; 696 + my $name = <$fh>; 696 697 chomp($name); 697 - my $version = <FILE>; 698 + my $version = <$fh>; 698 699 chomp($version); 699 - my $efi = <FILE>; 700 + my $efi = <$fh>; 700 701 chomp($efi); 701 - my $devices = <FILE>; 702 + my $devices = <$fh>; 702 703 chomp($devices); 703 - my $efiMountPoint = <FILE>; 704 + my $efiMountPoint = <$fh>; 704 705 chomp($efiMountPoint); 705 706 # Historically, arguments in the state file were one per each line, but that 706 707 # gets really messy when newlines are involved, structured arguments ··· 708 709 # when we need to remove a setting in the future. Thus, the 6th line is a JSON 709 710 # object that can store structured data, with named keys, and all new state 710 711 # should go in there. 711 - my $jsonStateLine = <FILE>; 712 + my $jsonStateLine = <$fh>; 712 713 # For historical reasons we do not check the values above for un-definedness 713 714 # (that is, when the state file has too few lines and EOF is reached), 714 715 # because the above come from the first version of this logic and are thus ··· 720 721 } 721 722 my %jsonState = %{decode_json($jsonStateLine)}; 722 723 my @extraGrubInstallArgs = exists($jsonState{'extraGrubInstallArgs'}) ? @{$jsonState{'extraGrubInstallArgs'}} : (); 723 - close FILE; 724 + close $fh; 724 725 my $grubState = GrubState->new(name => $name, version => $version, efi => $efi, devices => $devices, efiMountPoint => $efiMountPoint, extraGrubInstallArgs => \@extraGrubInstallArgs ); 725 726 return $grubState 726 727 } ··· 787 788 my $stateFile = "$bootPath/grub/state"; 788 789 my $stateFileTmp = $stateFile . ".tmp"; 789 790 790 - open FILE, ">$stateFileTmp" or die "cannot create $stateFileTmp: $!\n"; 791 - print FILE get("fullName"), "\n" or die; 792 - print FILE get("fullVersion"), "\n" or die; 793 - print FILE $efiTarget, "\n" or die; 794 - print FILE join( ",", @deviceTargets ), "\n" or die; 795 - print FILE $efiSysMountPoint, "\n" or die; 791 + open my $fh, ">", "$stateFileTmp" or die "cannot create $stateFileTmp: $!\n"; 792 + print $fh get("fullName"), "\n" or die; 793 + print $fh get("fullVersion"), "\n" or die; 794 + print $fh $efiTarget, "\n" or die; 795 + print $fh join( ",", @deviceTargets ), "\n" or die; 796 + print $fh $efiSysMountPoint, "\n" or die; 796 797 my %jsonState = ( 797 798 extraGrubInstallArgs => \@extraGrubInstallArgs 798 799 ); 799 800 my $jsonStateLine = encode_json(\%jsonState); 800 - print FILE $jsonStateLine, "\n" or die; 801 - close FILE or die; 801 + print $fh $jsonStateLine, "\n" or die; 802 + close $fh or die; 802 803 803 804 # Atomically switch to the new state file 804 805 rename $stateFileTmp, $stateFile or die "cannot rename $stateFileTmp to $stateFile: $!\n";