From 4811063c909dd6baa1dc2bddf035fdf597f4741c Mon Sep 17 00:00:00 2001 From: Lukas Rusak Date: Fri, 22 Feb 2019 11:40:50 -0800 Subject: [PATCH] config/functions: add safe_remove to notify if a file doesn't exist --- config/functions | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/config/functions b/config/functions index 050498b604..795553495a 100644 --- a/config/functions +++ b/config/functions @@ -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