Skip to content

Commit c91ce02

Browse files
committed
install: Extract function for creating absolute paths and reuse it
1 parent 766a7c2 commit c91ce02

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

src/etc/install.sh

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@ validate_opt () {
189189
done
190190
}
191191

192+
absolutify() {
193+
FILE_PATH="${1}"
194+
FILE_PATH_DIRNAME="$(dirname ${FILE_PATH})"
195+
FILE_PATH_BASENAME="$(basename ${FILE_PATH})"
196+
FILE_ABS_PATH="$(cd ${FILE_PATH_DIRNAME} && pwd)"
197+
FILE_PATH="${FILE_ABS_PATH}/${FILE_PATH_BASENAME}"
198+
# This is the return value
199+
ABSOLUTIFIED="${FILE_PATH}"
200+
}
201+
192202
CFG_SRC_DIR="$(cd $(dirname $0) && pwd)/"
193203
CFG_SELF="$0"
194204
CFG_ARGS="$@"
@@ -268,8 +278,13 @@ then
268278
err "can't install to same directory as installer"
269279
fi
270280

281+
# Using an absolute path to libdir in a few places so that the status
282+
# messages are consistently using absolute paths.
283+
absolutify "${CFG_LIBDIR}"
284+
ABS_LIBDIR="${ABSOLUTIFIED}"
285+
271286
# The file name of the manifest we're going to create during install
272-
INSTALLED_MANIFEST="${CFG_LIBDIR}/rustlib/manifest"
287+
INSTALLED_MANIFEST="${ABS_LIBDIR}/rustlib/manifest"
273288

274289
# First, uninstall from the installation prefix.
275290
# Errors are warnings - try to rm everything in the manifest even if some fail.
@@ -293,14 +308,14 @@ then
293308

294309
# If we fail to remove rustlib below, then the installed manifest will
295310
# still be full; the installed manifest needs to be empty before install.
296-
msg "removing ${CFG_LIBDIR}/rustlib/manifest"
297-
rm -f "${CFG_LIBDIR}/rustlib/manifest"
311+
msg "removing ${INSTALLED_MANIFEST}"
312+
rm -f "${INSTALLED_MANIFEST}"
298313
# For the above reason, this is a hard error
299314
need_ok "failed to remove installed manifest"
300315

301316
# Remove 'rustlib' directory
302-
msg "removing ${CFG_LIBDIR}/rustlib"
303-
rm -Rf "${CFG_LIBDIR}/rustlib"
317+
msg "removing ${ABS_LIBDIR}/rustlib"
318+
rm -Rf "${ABS_LIBDIR}/rustlib"
304319
if [ $? -ne 0 ]
305320
then
306321
warn "failed to remove rustlib"
@@ -325,6 +340,7 @@ fi
325340
# Create the installed manifest, which we will fill in with absolute file paths
326341
mkdir -p "${CFG_LIBDIR}/rustlib"
327342
touch "${INSTALLED_MANIFEST}"
343+
need_ok "failed to create installed manifest"
328344

329345
# Now install, iterate through the new manifest and copy files
330346
while read p; do
@@ -350,10 +366,8 @@ while read p; do
350366

351367
# Make the path absolute so we can uninstall it later without
352368
# starting from the installation cwd
353-
FILE_INSTALL_PATH_DIRNAME="$(dirname ${FILE_INSTALL_PATH})"
354-
FILE_INSTALL_PATH_BASENAME="$(basename ${FILE_INSTALL_PATH})"
355-
FILE_INSTALL_ABS_PATH="$(cd ${FILE_INSTALL_PATH_DIRNAME} && pwd)"
356-
FILE_INSTALL_PATH="${FILE_INSTALL_ABS_PATH}/${FILE_INSTALL_PATH_BASENAME}"
369+
absolutify "${FILE_INSTALL_PATH}"
370+
FILE_INSTALL_PATH="${ABSOLUTIFIED}"
357371

358372
# Install the file
359373
msg "${FILE_INSTALL_PATH}"

0 commit comments

Comments
 (0)