Skip to content

Commit eed808b

Browse files
committed
install: Improve error handling
1 parent 169f08d commit eed808b

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

src/etc/install.sh

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -224,49 +224,66 @@ step_msg "validating $CFG_SELF args"
224224
validate_opt
225225

226226
# Sanity check: can we can write to the destination?
227-
mkdir -p "${CFG_PREFIX}/lib"
227+
umask 022 && mkdir -p "${CFG_PREFIX}/lib"
228+
need_ok "directory creation failed"
228229
touch "${CFG_PREFIX}/lib/rust-install-probe" 2> /dev/null
229230
if [ $? -ne 0 ]
230231
then
231232
err "can't write to destination. try again with 'sudo'."
232233
fi
233-
rm -r "${CFG_PREFIX}/lib/rust-install-probe"
234+
rm "${CFG_PREFIX}/lib/rust-install-probe"
234235
need_ok "failed to remove install probe"
235236

236237
# Sanity check: can we run these binaries?
237238
"${CFG_SRC_DIR}/bin/rustc" --version > /dev/null
238239
need_ok "can't run these binaries on this platform"
239240

240241

241-
# First, uninstall from the installation prefix
242+
# First, uninstall from the installation prefix.
243+
# Errors are warnings - try to rm everything in the manifest even if some fail.
242244
# FIXME: Hardcoded 'rustlib' ignores CFG_RUSTLIBDIR
243245
if [ -f "${CFG_PREFIX}/lib/rustlib/manifest" ]
244246
then
247+
# Iterate through installed manifest and remove files
245248
while read p; do
246-
msg "uninstall ${CFG_PREFIX}/$p"
247-
rm "${CFG_PREFIX}/$p"
248-
need_ok "failed to remove file"
249+
msg "removing ${CFG_PREFIX}/$p"
250+
if [ -f "${CFG_PREFIX}/$p" ]
251+
then
252+
rm "${CFG_PREFIX}/$p"
253+
if [ $? -ne 0 ]
254+
then
255+
warn "failed to remove ${CFG_PREFIX}/$p"
256+
fi
257+
else
258+
warn "supposedly installed file ${CFG_PREFIX}/$p does not exist!"
259+
fi
249260
done < "${CFG_PREFIX}/lib/rustlib/manifest"
250261

251262
# Remove 'rustlib' directory
252-
msg "uninstall ${CFG_PREFIX}/lib/rustlib"
263+
msg "removing ${CFG_PREFIX}/lib/rustlib"
253264
rm -r "${CFG_PREFIX}/lib/rustlib"
254-
need_ok "failed to remove rustlib"
265+
if [ $? -ne 0 ]
266+
then
267+
warn "failed to remove rustlib"
268+
fi
255269
else
256270
if [ -n "${CFG_UNINSTALL}" ]
257271
then
258-
err "unable to find manifest at ${CFG_PREFIX}/lib/rustlib"
259-
exit 0
272+
err "unable to find installation manifest at ${CFG_PREFIX}/lib/rustlib"
260273
fi
261274
fi
262275

263276
# If we're only uninstalling then exit
264277
if [ -n "${CFG_UNINSTALL}" ]
265278
then
279+
echo
280+
echo " Rust is uninstalled. Have a nice day."
281+
echo
266282
exit 0
267283
fi
268284

269-
# Iterate through the new manifest and install files
285+
286+
# Now install, iterate through the new manifest and copy files
270287
while read p; do
271288

272289
umask 022 && mkdir -p "${CFG_PREFIX}/$(dirname $p)"

0 commit comments

Comments
 (0)