From fc2a2dc3d7106ab45f7cb873614c56b0921fec86 Mon Sep 17 00:00:00 2001 From: jthomas Date: Wed, 13 Aug 2003 02:14:46 +0000 Subject: [PATCH] added new function to resolve_symlink to grub-install.in moved code from find_device to this function install_device is now run through the new function --- ChangeLog | 7 +++++++ util/grub-install.in | 38 +++++++++++++++++++++++++------------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 46983c6dc..51c430130 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2003-08-13 Jason Thomas + + * util/grub-install.in (resolve_symlink): New function to resolve symlinks + (find_device): moved symlink code to new function + Before we convert the install_device we attempt to resolve it if its a + symlink using the new function + 2003-06-17 Jochen Hoenicke * stage2/fsys_reiserfs.c (read_tree_node): Fixed a typo; only diff --git a/util/grub-install.in b/util/grub-install.in index 4cf263b09..c6131d082 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -181,6 +181,29 @@ convert () { fi } +# Usage: resolve_symlink file +# Find the real file/device that file points at +resolve_symlink () { + tmp_fname=$1 + # Resolve symlinks + while test -L $tmp_fname; do + tmp_new_fname=`ls -al $tmp_fname | sed -n 's%.*-> \(.*\)%\1%p'` + if test -z "$tmp_new_fname"; then + echo "Unrecognized ls output" 2>&1 + exit 1 + fi + + # Convert relative symlinks + case $tmp_new_fname in + /*) tmp_fname="$tmp_new_fname" + ;; + *) tmp_fname="`echo $tmp_fname | sed 's%/[^/]*$%%'`/$tmp_new_fname" + ;; + esac + done + echo "$tmp_fname" +} + # Usage: find_device file # Find block device on which the file resides. find_device () { @@ -193,20 +216,8 @@ find_device () { exit 1 fi - # Resolve symlinks - while test -L $tmp_fname; do - tmp_new_fname=`ls -al $tmp_fname | sed -n 's%.*-> \(.*\)%\1%p'` - if test -z "$tmp_new_fname"; then - echo "Unrecognized ls output" 2>&1 - exit 1 - fi + tmp_fname=`resolve_symlink $tmp_fname` - # Convert relative symlinks - case $tmp_new_fname in - /*) tmp_fname="$tmp_new_fname" ;; - *) tmp_fname="`echo $tmp_fname | sed 's%/[^/]*$%%'`/$tmp_new_fname" ;; - esac - done echo "$tmp_fname" } @@ -338,6 +349,7 @@ fi # Check for INSTALL_DEVICE. case "$install_device" in /dev/*) + install_device=`resolve_symlink "$install_device"` install_drive=`convert "$install_device"` # I don't know why, but some shells wouldn't die if exit is # called in a function.