summaryrefslogtreecommitdiffstats
path: root/functions
diff options
context:
space:
mode:
authorDave Reisner <d@falconindy.com>2011-06-16 20:22:28 +0200
committerDave Reisner <d@falconindy.com>2011-06-16 20:23:32 +0200
commit9aa3d55fcd611ec1833ba885f06637784105ac90 (patch)
tree4c5253807965d8ca1c5f3360f1e18e630e61c495 /functions
parentb117e2ae0cf948d4afe59eee6e503f30f184ddba (diff)
downloadmkinitcpio-9aa3d55fcd611ec1833ba885f06637784105ac90.tar.gz
mkinitcpio-9aa3d55fcd611ec1833ba885f06637784105ac90.tar.xz
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 <d@falconindy.com>
Diffstat (limited to 'functions')
-rw-r--r--functions37
1 files changed, 15 insertions, 22 deletions
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
}