summaryrefslogtreecommitdiff
path: root/lib/common.sh
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common.sh')
-rw-r--r--lib/common.sh90
1 files changed, 45 insertions, 45 deletions
diff --git a/lib/common.sh b/lib/common.sh
index 9f537c7..c6c5993 100644
--- a/lib/common.sh
+++ b/lib/common.sh
@@ -107,48 +107,76 @@ in_array() {
}
##
-# usage : lock_open_write( $fd, $path.lock, $wait_message )
+# usage : get_full_version( [$pkgname] )
+# return : full version spec, including epoch (if necessary), pkgver, pkgrel
##
-lock_open_write() {
+get_full_version() {
+ # set defaults if they weren't specified in buildfile
+ pkgbase=${pkgbase:-${pkgname[0]}}
+ epoch=${epoch:-0}
+ if [[ -z $1 ]]; then
+ if [[ $epoch ]] && (( ! $epoch )); then
+ echo $pkgver-$pkgrel
+ else
+ echo $epoch:$pkgver-$pkgrel
+ fi
+ else
+ for i in pkgver pkgrel epoch; do
+ local indirect="${i}_override"
+ eval $(declare -f package_$1 | sed -n "s/\(^[[:space:]]*$i=\)/${i}_override=/p")
+ [[ -z ${!indirect} ]] && eval ${indirect}=\"${!i}\"
+ done
+ if (( ! $epoch_override )); then
+ echo $pkgver_override-$pkgrel_override
+ else
+ echo $epoch_override:$pkgver_override-$pkgrel_override
+ fi
+ fi
+}
+
+##
+# usage : lock( $fd, $file, $message )
+##
+lock() {
local fd=$1
- local path=$2
- local msg=$3
+ local file=$2
+ local mesg=$3
# Only reopen the FD if it wasn't handed to us
- if [[ "$(readlink -f /dev/fd/$fd)" != "$(readlink -f "${path}")" ]]; then
- mkdir -p "${path%/*}"
- eval "exec $fd>${path}"
+ if [[ "$(readlink -f /dev/fd/$fd)" != "$(readlink -f "$file")" ]]; then
+ mkdir -p "${file%/*}"
+ eval "exec $fd>"'"$file"'
fi
if ! flock -n $fd; then
- stat_busy "$msg"
+ stat_busy "$mesg"
flock $fd
stat_done
fi
}
##
-# usage : lock_open_read( $fd, $path.lock, $wait_message )
+# usage : slock( $fd, $file, $message )
##
-lock_open_read() {
+slock() {
local fd=$1
- local path=$2
- local msg=$3
+ local file=$2
+ local mesg=$3
# Only reopen the FD if it wasn't handed to us
- if [[ "$(readlink -f /dev/fd/$fd)" != "$(readlink -f "${path}")" ]]; then
- mkdir -p "${path%/*}"
- eval "exec $fd>${path}"
+ if [[ "$(readlink -f /dev/fd/$fd)" != "$(readlink -f "$file")" ]]; then
+ mkdir -p "${file%/*}"
+ eval "exec $fd>"'"$file"'
fi
+ eval "exec $fd>"'"$file"'
if ! flock -sn $fd; then
- stat_busy "$msg"
+ stat_busy "$mesg"
flock -s $fd
stat_done
fi
}
-
##
# usage : lock_close( $fd )
##
@@ -156,31 +184,3 @@ lock_close() {
local fd=$1
eval "exec $fd>&-"
}
-
-##
-# usage : get_full_version( [$pkgname] )
-# return : full version spec, including epoch (if necessary), pkgver, pkgrel
-##
-get_full_version() {
- # set defaults if they weren't specified in buildfile
- pkgbase=${pkgbase:-${pkgname[0]}}
- epoch=${epoch:-0}
- if [[ -z $1 ]]; then
- if [[ $epoch ]] && (( ! $epoch )); then
- echo $pkgver-$pkgrel
- else
- echo $epoch:$pkgver-$pkgrel
- fi
- else
- for i in pkgver pkgrel epoch; do
- local indirect="${i}_override"
- eval $(declare -f package_$1 | sed -n "s/\(^[[:space:]]*$i=\)/${i}_override=/p")
- [[ -z ${!indirect} ]] && eval ${indirect}=\"${!i}\"
- done
- if (( ! $epoch_override )); then
- echo $pkgver_override-$pkgrel_override
- else
- echo $epoch_override:$pkgver_override-$pkgrel_override
- fi
- fi
-}