config/functions: add safe_remove to notify if a file doesn't exist

This commit is contained in:
Lukas Rusak 2019-02-22 11:40:50 -08:00
parent c71997a775
commit 4811063c90
No known key found for this signature in database
GPG Key ID: 8C310C807E7393A3

View File

@ -129,6 +129,21 @@ build_msg() {
fi
}
# prints a warning if the file slated for removal doesn't exist
# this allows us to continue instead of bailing out with just "rm"
safe_remove() {
local path="$1"
[ -z "${path}" ] && return 0
if [ -f "${path}" -o -d "${path}" ]; then
rm -r "${path}"
elif [ -n "${PKG_NAME}" ]; then
print_color CLR_WARNING "safe_remove: path does not exist: [${PKG_NAME}]: ${path}\n"
else
print_color CLR_WARNING "safe_remove: path does not exist: ${path}\n"
fi
}
### BUILDSYSTEM HELPERS ###
# check if a flag is enabled