Skip to contentSkip to conversation

inst_symlink: create parent dir if doesn't exist

PATCH In review Amadeusz Żołnowski 1 participant 3 messages Mar 25, 2012 – Mar 26, 2012 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 inst_symlink: create parent dir if doesn't exist

If symlink is yet alone in target directory, inst_symlink will fail to create it. This is how to reproduce the bug:

 # mkdir /tmp/test
 # ln -s /bin/cp /tmp/test/cp
 # ./dracut -l -f -H /tmp/test.img -I /tmp/test/cp

Result:

[...]

I: *** Including modules done ***
ln: failed to create symbolic link `/var/tmp/initramfs.Z5isVu//tmp/test/cp': No such file or directory
ln: failed to create symbolic link `/var/tmp/initramfs.Z5isVu//tmp/test/cp': No such file or directory
I: Wrote /tmp/test.img:

[...]

Following patch creates directory for the symlink if it doesn't exist.

---
 dracut-functions.sh |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
dracut-functions.sh +3 -0
index f4ccf53..adca47d 100755
@@ -545,8 +545,11 @@ inst_symlink() {
             inst "$_realsrc"
         fi
     fi
+    set -x
+    [[ ! -e $initdir/${_target%/*} ]] && inst_dir "${_target%/*}"
     [[ -d ${_target%/*} ]] && _target=$(readlink -f ${_target%/*})/${_target##*/}
     ln -sfn $(convert_abs_rel "${_target}" "${_realsrc}") "$initdir/$_target"
+    set +x
 }
 
 # attempt to install any programs specified in a udev rule
Signature · 1 line
1.7.8.5
#2 lore raw
In reply to a message not in the archive

Excerpts from Amadeusz Żołnowski's message of 2012-03-26 00:11:53 +0200:

dracut-functions.sh inst_symlink() { · line 552

Quoted 5 lines
dracut-functions.sh +3 -0
+    set -x
+    [[ ! -e $initdir/${_target%/*} ]] && inst_dir "${_target%/*}"
     [[ -d ${_target%/*} ]] && _target=$(readlink -f ${_target%/*})/${_target##*/}
     ln -sfn $(convert_abs_rel "${_target}" "${_realsrc}") "$initdir/$_target"
+    set +x

Sorry, I have forgot to remove debug. Corrected patch in next post.

Signature · 1 line
Amadeusz Żołnowski
#3 lore raw

PATCH 1/1 inst_symlink: create parent dir if doesn't exist

In reply to a message not in the archive

If symlink is yet alone in target directory, inst_symlink will fail to create it. This is how to reproduce the bug:

 # mkdir /tmp/test
 # ln -s /bin/cp /tmp/test/cp
 # ./dracut -l -f -H /tmp/test.img -I /tmp/test/cp

Result:

[...]

I: *** Including modules done ***
ln: failed to create symbolic link `/var/tmp/initramfs.Z5isVu//tmp/test/cp': No such file or directory
ln: failed to create symbolic link `/var/tmp/initramfs.Z5isVu//tmp/test/cp': No such file or directory
I: Wrote /tmp/test.img:

[...]

Following patch creates directory for the symlink if it doesn't exist.

---
 dracut-functions.sh |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
dracut-functions.sh +1 -0
index f4ccf53..8082466 100755
@@ -545,6 +545,7 @@ inst_symlink() {
             inst "$_realsrc"
         fi
     fi
+    [[ ! -e $initdir/${_target%/*} ]] && inst_dir "${_target%/*}"
     [[ -d ${_target%/*} ]] && _target=$(readlink -f ${_target%/*})/${_target##*/}
     ln -sfn $(convert_abs_rel "${_target}" "${_realsrc}") "$initdir/$_target"
 }
Signature · 1 line
1.7.8.5