libmakepkg: extract more utility functions
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
8ab106eb9b
commit
15b6cecdd5
2 changed files with 31 additions and 31 deletions
|
@ -19,7 +19,7 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# 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
|
LIBMAKEPKG_UTIL_UTIL_SH=1
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,3 +36,33 @@ in_array() {
|
||||||
done
|
done
|
||||||
return 1 # Not Found
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -1415,14 +1415,6 @@ error_function() {
|
||||||
exit 2 # $E_BUILD_FAILED
|
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() {
|
source_safe() {
|
||||||
shopt -u extglob
|
shopt -u extglob
|
||||||
if ! source "$@"; then
|
if ! source "$@"; then
|
||||||
|
@ -2380,28 +2372,6 @@ print_all_package_names() {
|
||||||
done
|
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)
|
m4_include(library/parseopts.sh)
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue