summaryrefslogtreecommitdiff
path: root/lib/common.sh
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-06-15 11:20:37 -0600
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-06-15 11:20:37 -0600
commita8c95177c7f9bab8cb7e697c6e925b2fb1c5d342 (patch)
treeed43f04c4e2aaab033aba23fae4ead687555ca9b /lib/common.sh
parenta7ee45d6259e84628599f721abc297f935504fee (diff)
parenta7a05deb37b3db6aa3606f488467f621c40ce32d (diff)
downloaddevtools32-a8c95177c7f9bab8cb7e697c6e925b2fb1c5d342.tar.xz
Merge commit 'a7a0': merge our and their lock functions
Arch's have shorter names, and properly escape the filename. Ours create the directories, and check if the locks are already open. The best of both worlds. When merging the usages of them, I used arch's messages. Ours are too long, even if they are more informative.
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
-}