Skip to content

Commit 7294f01

Browse files
committed
install.sh: Join split absolutify functions
1 parent 2ccfecc commit 7294f01

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

install-template.sh

+13-17
Original file line numberDiff line numberDiff line change
@@ -307,30 +307,26 @@ absolutify() {
307307
local file_path="$1"
308308
local file_path_dirname="${file_path%/*}"
309309
local file_path_basename="${file_path##*/}"
310-
abs_path_cached "$file_path_dirname"
311-
local file_abs_path="$abs_path_cached_retval"
310+
local file_abs_path
311+
# Update cached abs path only if the argument differs from the last invocation
312+
if [ ! "$file_path_dirname" = "${_absolutiy_file_path_dirname-}" ]
313+
then
314+
_absolutiy_file_path_dirname="$file_path_dirname"
315+
# Unset CDPATH because it causes havok: it makes the destination unpredictable
316+
# and triggers 'cd' to print the path to stdout. Route `cd`'s output to /dev/null
317+
# for good measure.
318+
_absolutiy_file_abs_path="$(CDPATH= cd "$file_path_dirname" > /dev/null && pwd)"
319+
fi
320+
file_abs_path="${_absolutiy_file_abs_path-}"
312321
local file_path="$file_abs_path/$file_path_basename"
313322
# This is the return value
314323
RETVAL="$file_path"
315324
}
316325

317326
# Prints the absolute path of a directory to stdout
318327
abs_path() {
319-
abs_path_cached "$@"
320-
printf %s "$abs_path_cached_retval"
321-
}
322-
323-
abs_path_cached() {
324-
local path="$1"
325-
# Update return value only if the argument differs from the last invocation
326-
if ! [ "$path" = "${_abs_path_cached_key:-}" ]
327-
then
328-
_abs_path_cached_key="$path"
329-
# Unset CDPATH because it causes havok: it makes the destination unpredictable
330-
# and triggers 'cd' to print the path to stdout. Route `cd`'s output to /dev/null
331-
# for good measure.
332-
abs_path_cached_retval="$(unset CDPATH && cd "$path" > /dev/null && pwd)"
333-
fi
328+
absolutify "$@"
329+
printf %s "$RETVAL"
334330
}
335331

336332
uninstall_legacy() {

0 commit comments

Comments
 (0)