Skip to content

Commit 35a394e

Browse files
committed
removed dependency on uuid, minor fixes
1 parent accf251 commit 35a394e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

gitlock

+13-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ tagtrylock() {
1313

1414
showlock() {
1515
TAG="$1"
16-
echo "$1"
1716
git tag -l --format='%0auser%09%09%(taggername)%0a%0a%(body)' $TAG | grep '.' || return 1
1817
echo ""
1918
}
@@ -108,7 +107,7 @@ lockloop() {
108107
LASTLOCKEDTAG="__"
109108
TAG=""
110109
while true; do # in fact there must be timeout or number of tries limit
111-
TAG="lock-$(uuid -v4)"
110+
TAG="lock-$(cat /dev/urandom | head -c 256 | sha1sum | cut -d " " -f1)"
112111
LOCKEDTAG=""
113112
cycle "$TAG" "$OPERATION"
114113
RESULT="$?"
@@ -196,6 +195,8 @@ while [ "$1" != "" ]; do
196195
echo "lock name must be provided"
197196
exit 1
198197
fi
198+
199+
echo "$2"
199200
showlock "$2"
200201
if [[ "$?" != 0 ]]; then
201202
echo "error during getting lock info. No such lock?"
@@ -257,9 +258,17 @@ TAG=""
257258

258259
lockloop "$OPERATION" || exit $?
259260
echo "Acquired lock $TAG"
261+
262+
cleanup() {
263+
clean "$TAG"
264+
}
265+
266+
trap cleanup EXIT
267+
260268
("$@")
269+
RESULT="$?"
261270

262271
echo "Releasing lock $TAG"
263-
clean "$TAG"
272+
clean "$TAG" || true
264273

265-
exit $?
274+
exit $RESULT

0 commit comments

Comments
 (0)