
Currently when we add an image, we check if the default image
starts with /boot, and if not we remove /boot from the new kernel
and initrd names.  This is designed to cope with the situation where
where /boot is its own partion and image names are /vmlinux.

However, this is falsly triggered where there is any device prefix as
can occur in grub:

	image (hd0,0)/boot/vmlinux

This leads us to incorrectly produce entries like:

	image /mykernel

rather than:

	image (hd0,0)/boot/mykernel

This patch changes the algorithm to remove the "filename" from the end
whatever is left then becomes the prefix if the file is in /boot, if
it is not the caller is expected to know what they are doing.  Frankly,
its not clear that we support booting files in any other directory.

Signed-off-by: Andy Whitcroft <apw@shadowen.org>
---
 client/tools/boottool |   27 +++++++++++++++------------
 1 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/client/tools/boottool b/client/tools/boottool
index 62dd724..0171fee 100755
--- a/client/tools/boottool
+++ b/client/tools/boottool
@@ -363,10 +363,11 @@ sub add {
   }
 
   # use default entry to determine if path (/boot) should be removed
-  if ($sections[$default]{'kernel'} !~ /^\/boot/) {
-    $param{'add-kernel'} =~ s/^\/boot//;
-    $param{'initrd'} =~ s/^\/boot// unless (!defined $param{'initrd'});
-  }
+  my $bootpath = $sections[$default]{'kernel'};
+  $bootpath =~ s@[^/]*$@@;
+
+  $param{'add-kernel'} =~ s@^/boot/@$bootpath@;
+  $param{'initrd'} =~ s@^/boot/@$bootpath@ unless !defined $param{'initrd'};
 
   my @newkernel;
   push (@newkernel, "image=$param{'add-kernel'}\n", "\tlabel=$param{title}\n");
@@ -1360,10 +1361,11 @@ sub add {
   }
 
   # use default entry to determine if path (/boot) should be removed
-  if ($sections[$default]{'kernel'} !~ /^\/boot/) {
-    $param{'add-kernel'} =~ s/^\/boot//;
-    $param{'initrd'} =~ s/^\/boot// unless !defined $param{'initrd'};
-  }
+  my $bootpath = $sections[$default]{'kernel'};
+  $bootpath =~ s@[^/]*$@@;
+
+  $param{'add-kernel'} =~ s@^/boot/@$bootpath@;
+  $param{'initrd'} =~ s@^/boot/@$bootpath@ unless !defined $param{'initrd'};
 
   my @newkernel;
   push(@newkernel, "title\t$param{title}\n") if defined $param{title};
@@ -2070,10 +2072,11 @@ sub add {
   }
 
   # use default entry to determine if path (/boot) should be removed
-  if ($sections[$default]{'kernel'} !~ /^\/boot/) {
-    $param{'add-kernel'} =~ s/^\/boot//;
-    $param{'initrd'} =~ s/^\/boot// unless !defined $param{'initrd'};
-  }
+  my $bootpath = $sections[$default]{'kernel'};
+  $bootpath =~ s@[^/]*$@@;
+
+  $param{'add-kernel'} =~ s@^/boot/@$bootpath@;
+  $param{'initrd'} =~ s@^/boot/@$bootpath@ unless !defined $param{'initrd'};
 
   my $line;
   my @newkernel;
