@@ -37,7 +37,8 @@ sub readFile {
3737 my ($fn ) = @_ ;
3838 # enable slurp mode: read entire file in one go
3939 local $/ = undef ;
40- open my $fh , " <$fn " or return undef ;
40+ open my $fh , " <" , $fn
41+ or return ;
4142 my $s = <$fh >;
4243 close $fh ;
4344 # disable slurp mode
@@ -48,7 +49,7 @@ sub readFile {
4849
4950sub writeFile {
5051 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 " ;
5253 print $fh $s or die " cannot write to $fn : $! \n " ;
5354 close $fh or die " cannot close $fn : $! \n " ;
5455}
@@ -690,25 +691,25 @@ sub getEfiTarget {
690691# because it is read line-by-line.
691692sub readGrubState {
692693 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 ;
694695 local $/ = " \n " ;
695- my $name = <FILE >;
696+ my $name = <$fh >;
696697 chomp ($name );
697- my $version = <FILE >;
698+ my $version = <$fh >;
698699 chomp ($version );
699- my $efi = <FILE >;
700+ my $efi = <$fh >;
700701 chomp ($efi );
701- my $devices = <FILE >;
702+ my $devices = <$fh >;
702703 chomp ($devices );
703- my $efiMountPoint = <FILE >;
704+ my $efiMountPoint = <$fh >;
704705 chomp ($efiMountPoint );
705706 # Historically, arguments in the state file were one per each line, but that
706707 # gets really messy when newlines are involved, structured arguments
707708 # like lists are needed (they have to have a separator encoding), or even worse,
708709 # when we need to remove a setting in the future. Thus, the 6th line is a JSON
709710 # object that can store structured data, with named keys, and all new state
710711 # should go in there.
711- my $jsonStateLine = <FILE >;
712+ my $jsonStateLine = <$fh >;
712713 # For historical reasons we do not check the values above for un-definedness
713714 # (that is, when the state file has too few lines and EOF is reached),
714715 # because the above come from the first version of this logic and are thus
@@ -720,7 +721,7 @@ sub readGrubState {
720721 }
721722 my %jsonState = %{decode_json($jsonStateLine )};
722723 my @extraGrubInstallArgs = exists ($jsonState {' extraGrubInstallArgs' }) ? @{$jsonState {' extraGrubInstallArgs' }} : ();
723- close FILE ;
724+ close $fh ;
724725 my $grubState = GrubState-> new(name => $name , version => $version , efi => $efi , devices => $devices , efiMountPoint => $efiMountPoint , extraGrubInstallArgs => \@extraGrubInstallArgs );
725726 return $grubState
726727}
@@ -787,18 +788,18 @@ sub readGrubState {
787788 my $stateFile = " $bootPath /grub/state" ;
788789 my $stateFileTmp = $stateFile . " .tmp" ;
789790
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 ;
796797 my %jsonState = (
797798 extraGrubInstallArgs => \@extraGrubInstallArgs
798799 );
799800 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 ;
802803
803804 # Atomically switch to the new state file
804805 rename $stateFileTmp , $stateFile or die " cannot rename $stateFileTmp to $stateFile : $! \n " ;
0 commit comments