index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
author | Allan McRae <allan@archlinux.org> | 2015-05-13 15:44:01 +1000 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2015-05-19 23:43:00 +1000 |
commit | 15b6cecdd5353d1ce8d8a9747ea9e55477ceb3fb (patch) | |
tree | 118f7462f06430d00edf2f16b20b7350ead55ec4 /scripts/libmakepkg/util/util.sh | |
parent | 8ab106eb9b21263941a4329eb89709f35b2bd178 (diff) |
-rw-r--r-- | scripts/libmakepkg/util/util.sh | 32 |
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 <http://www.gnu.org/licenses/>. # -[ -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 +} |