3
0
Fork 0
forked from mirrors/nixpkgs

grub: Fix incorrect upgrade to new jsonStateLine. See #85895. (#92520)

Fixes error

    Can't use an undefined value as an ARRAY reference at /nix/store/...-install-grub.pl line 642, <FILE> line 5.

with `/boot/grub/state` being:

```
grub
2.04
no
/dev/sda
/boot

```

I am not sure where the trailing empty line can come from; the script does not
seem to write it. In any case, now we handle that situation as well.

Further, ensure that `extraGrubInstallArgs` defaults to the empty array
if its key is not present in the `jsonState`.
This commit is contained in:
Niklas Hambüchen 2020-07-07 00:53:55 +02:00 committed by GitHub
parent 11eb84bb9f
commit e8c1ff9ef8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -638,8 +638,11 @@ sub readGrubState {
# guaranteed to be present. # guaranteed to be present.
$jsonStateLine = defined $jsonStateLine ? $jsonStateLine : '{}'; # empty JSON object $jsonStateLine = defined $jsonStateLine ? $jsonStateLine : '{}'; # empty JSON object
chomp($jsonStateLine); chomp($jsonStateLine);
if ($jsonStateLine eq "") {
$jsonStateLine = '{}'; # empty JSON object
}
my %jsonState = %{decode_json($jsonStateLine)}; my %jsonState = %{decode_json($jsonStateLine)};
my @extraGrubInstallArgs = @{$jsonState{'extraGrubInstallArgs'}}; my @extraGrubInstallArgs = exists($jsonState{'extraGrubInstallArgs'}) ? @{$jsonState{'extraGrubInstallArgs'}} : ();
close FILE; close FILE;
my $grubState = GrubState->new(name => $name, version => $version, efi => $efi, devices => $devices, efiMountPoint => $efiMountPoint, extraGrubInstallArgs => \@extraGrubInstallArgs ); my $grubState = GrubState->new(name => $name, version => $version, efi => $efi, devices => $devices, efiMountPoint => $efiMountPoint, extraGrubInstallArgs => \@extraGrubInstallArgs );
return $grubState return $grubState