[Libguestfs] [PATCH] Fix detection of an existing grub entry
Richard W.M. Jones
rjones at redhat.com
Thu Jan 20 18:02:07 UTC 2011
On Thu, Jan 20, 2011 at 05:27:13PM +0000, Matthew Booth wrote:
> There were 2 issues in the code which checked for an existing grub entry before
> adding a new one.
>
> Firstly, it didn't take account of the fact that the passed-in kernel path is
> relative to root, whereas the grub entry is relative to the grub filesystem,
> which is normally /boot.
>
> Secondly, it expected return from inside eval{} to exit the function, when in
> fact it only exits the eval.
> ---
> lib/Sys/VirtV2V/Converter/RedHat.pm | 16 +++++++---------
> 1 files changed, 7 insertions(+), 9 deletions(-)
>
> diff --git a/lib/Sys/VirtV2V/Converter/RedHat.pm b/lib/Sys/VirtV2V/Converter/RedHat.pm
> index 0a4f829..d8f9141 100644
> --- a/lib/Sys/VirtV2V/Converter/RedHat.pm
> +++ b/lib/Sys/VirtV2V/Converter/RedHat.pm
> @@ -1500,23 +1500,21 @@ sub _check_grub
> {
> my ($version, $kernel, $g, $desc) = @_;
>
> + my $grubfs = $desc->{boot}->{grub_fs};
> + my $prefix = $grubfs eq '/boot' ? '' : '/boot';
> +
> # Nothing to do if there's already a grub entry
> - eval {
> + return if eval {
> foreach my $augpath
> ($g->aug_match('/files/boot/grub/menu.lst/title/kernel'))
> {
> - return if ($g->aug_get($augpath) eq $kernel);
> + return 1 if ($grubfs.$g->aug_get($augpath) eq $kernel);
> }
> +
> + return 0
> };
> augeas_error($g, $@) if ($@);
>
> - my $prefix;
> - if ($desc->{boot}->{grub_fs} eq "/boot") {
> - $prefix = '';
> - } else {
> - $prefix = '/boot';
> - }
> -
> my $initrd = "$prefix/initrd-$version.img";
> $kernel =~ m{^/boot/(.*)$} or die("kernel in unexpected location: $kernel");
> my $vmlinuz = "$prefix/$1";
ACK.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
libguestfs lets you edit virtual machines. Supports shell scripting,
bindings from many languages. http://libguestfs.org
More information about the Libguestfs
mailing list