File: ar_lock.sh

package info (click to toggle)
bart 0.9.00-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,040 kB
  • sloc: ansic: 116,116; python: 1,329; sh: 726; makefile: 639; javascript: 589; cpp: 106
file content (26 lines) | stat: -rwxr-xr-x 417 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash
set -e
if command -v flock > /dev/null ; then
	flock `dirname $2`/.`basename $2`.lock -c "ar $*"
	exit 0
fi

if command -v shlock > /dev/null ; then
	LOCK=/tmp/`basename $2`.lock
	trap 'rm -f ${LOCK} ; exit 1' 1 2 3 15

	while true ; do
		if shlock -p $$ -f ${LOCK} ; then
        		ar $*
			rm -rf ${LOCK}
			exit 0
		else
        		sleep 1
		fi
	done
fi

echo "Error: no flock/shlock command!"
exit 1