From 9aa3d55fcd611ec1833ba885f06637784105ac90 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Thu, 16 Jun 2011 14:22:28 -0400 Subject: functions: refactor add_file Properly detect symlinks using the -L shell test, resolving and recursing on discovery. This results in removing a lot of extraneous variable declarations and code. Signed-off-by: Dave Reisner --- functions | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) (limited to 'functions') diff --git a/functions b/functions index 662df7b..4219680 100644 --- a/functions +++ b/functions @@ -114,33 +114,26 @@ add_symlink () #fail quietly } -add_file () +add_file() { - local fil lnk dir dest - if [[ -f "$1" ]]; then - fil=$1 - lnk=$(readlink -f "${fil}") - if [[ ${lnk} ]]; then - add_symlink "${fil}" "${lnk}" - fil="${lnk}" - fi - if [[ $2 ]]; then - dest=$2 - else - dest="${fil##$BASEDIR}" - if [[ "${dest}" = "${dest#/}" ]]; then - dest="/${dest}" - fi - fi + local file dest - add_dir $(get_dirname "${dest}") + file=$1 + dest=${2:-${file##$BASEDIR}} - if [[ ! -e $TMPDIR/root/$dest ]]; then - msg " adding file ${dest}" - command install -Dm$(stat -c '%a' "$fil") "$fil" "$TMPDIR/root/$dest" + if [[ -f "$file" ]]; then + if [[ -L "$file" ]]; then + add_symlink "$file" "$(readlink -f "$file")" + add_file "$(readlink -f "$file")" + return + fi + + if [[ ! -e "$TMPDIR/root/$dest" ]]; then + msg " adding file $dest" + command install -Dm$(stat -c '%a' "$file") "$file" "$TMPDIR/root/$dest" fi else - err "file '${1}' does not exist" + err "file '$file' does not exist" return 1 fi } -- cgit v1.2.3-24-g4f1b