From 15b6cecdd5353d1ce8d8a9747ea9e55477ceb3fb Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Wed, 13 May 2015 15:44:01 +1000 Subject: libmakepkg: extract more utility functions Signed-off-by: Allan McRae --- scripts/libmakepkg/util/util.sh | 32 +++++++++++++++++++++++++++++++- scripts/makepkg.sh.in | 30 ------------------------------ 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/scripts/libmakepkg/util/util.sh b/scripts/libmakepkg/util/util.sh index 307464e4..d2378bb8 100644 --- a/scripts/libmakepkg/util/util.sh +++ b/scripts/libmakepkg/util/util.sh @@ -19,7 +19,7 @@ # along with this program. If not, see . # -[ -n "$LIBMAKEPKG_UTIL_UTIL_SH" ] && return +[[ -n "$LIBMAKEPKG_UTIL_UTIL_SH" ]] && return LIBMAKEPKG_UTIL_UTIL_SH=1 @@ -36,3 +36,33 @@ in_array() { done return 1 # Not Found } + +# Canonicalize a directory path if it exists +canonicalize_path() { + local path="$1"; + + if [[ -d $path ]]; then + ( + cd_safe "$path" + pwd -P + ) + else + printf "%s\n" "$path" + fi +} + +dir_is_empty() { + ( + shopt -s dotglob nullglob + files=("$1"/*) + (( ${#files} == 0 )) + ) +} + +cd_safe() { + if ! cd "$1"; then + error "$(gettext "Failed to change to directory %s")" "$1" + plain "$(gettext "Aborting...")" + exit 1 + fi +} diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 2d64997a..f88ec3cc 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1415,14 +1415,6 @@ error_function() { exit 2 # $E_BUILD_FAILED } -cd_safe() { - if ! cd "$1"; then - error "$(gettext "Failed to change to directory %s")" "$1" - plain "$(gettext "Aborting...")" - exit 1 - fi -} - source_safe() { shopt -u extglob if ! source "$@"; then @@ -2380,28 +2372,6 @@ print_all_package_names() { done } -# Canonicalize a directory path if it exists -canonicalize_path() { - local path="$1"; - - if [[ -d $path ]]; then - ( - cd_safe "$path" - pwd -P - ) - else - printf "%s\n" "$path" - fi -} - -dir_is_empty() { - ( - shopt -s dotglob nullglob - files=("$1"/*) - (( ${#files} == 0 )) - ) -} - m4_include(library/parseopts.sh) usage() { -- cgit v1.2.3-70-g09d2