From 36435d67730628e4b5f40e5b5cab1456ea2e7aa7 Mon Sep 17 00:00:00 2001 From: illiliti Date: Tue, 8 Sep 2020 23:32:54 +0300 Subject: [PATCH] handle case when file and dest have same basenames --- tinyramfs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tinyramfs b/tinyramfs index 08e017e..c104f5f 100755 --- a/tinyramfs +++ b/tinyramfs @@ -155,15 +155,17 @@ copy_file() # iterate throught symlinks and copy them while [ -h "$file" ]; do - cp -P "$file" "${tmpdir}${dest}" || panic + cp -P "$file" "${tmpdir}${dest%/*}/${file##*/}" cd -P "${file%/*}" symlink=$(ls -ld "$file") symlink="${symlink##* -> }" - file="${PWD}/${symlink##*/}" done + # handle case when file and dest have same basenames + [ -h "${tmpdir}${dest}" ] && dest="${dest%/*}/${file##*/}" + { cp "$file" "${tmpdir}${dest}" chmod "$mode" "${tmpdir}${dest}"