index : devtools32 | |
Archlinux32 fork of devtools | gitolite user |
summaryrefslogtreecommitdiff |
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2012-11-25 20:05:09 -0500 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2012-11-25 20:28:14 -0500 |
commit | e9836b6b2afa70f22d305509593b375543b20ba6 (patch) | |
tree | 9695c79202bb58c4014033f98a0021790f49817e /lib/common.sh | |
parent | 2343d5c3c034c2597a034f5a5de9373d7e076e60 (diff) |
-rw-r--r-- | lib/common.sh | 49 |
diff --git a/lib/common.sh b/lib/common.sh index b39bbbc..5204091 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -104,6 +104,55 @@ in_array() { } ## +# usage : lock_open_write( $fd, $path, $wait_message ) +## +lock_open_write() { + local fd=$1 + local path=$2 + local msg=$3 + + # Only reopen the FD if it wasn't handed to us + if [[ $(readlink -f /dev/fd/$fd) != "${path}.lock" ]]; then + eval "exec $fd>${path}.lock" + fi + + if ! flock -n $fd; then + stat_busy "$msg" + flock $fd + stat_done + fi +} + +## +# usage : lock_open_read( $fd, $path, $wait_message ) +## +lock_open_read() { + local fd=$1 + local path=$2 + local msg=$3 + + # Only reopen the FD if it wasn't handed to us + if [[ $(readlink -f /dev/fd/$fd) != "${path}.lock" ]]; then + eval "exec $fd>${path}.lock" + fi + + if ! flock -sn $fd; then + stat_busy "$msg" + flock -s $fd + stat_done + fi +} + + +## +# usage : lock_close( $fd ) +## +lock_close() { + local fd=$1 + eval "exec $fd>&-" +} + +## # usage : get_full_version( [$pkgname] ) # return : full version spec, including epoch (if necessary), pkgver, pkgrel ## |