-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathlock.sh
More file actions
68 lines (59 loc) · 1.79 KB
/
lock.sh
File metadata and controls
68 lines (59 loc) · 1.79 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# lockfile manager
lockfile_print_warning() {
PRINT WARNING "Lockfile error, check debug log for more information"
}
lock_create() {
if [[ $BLUEPRINT__FOLDER == "" ]]; then
PRINT DEBUG "(lock.sh) lockfile could not be locked, \$BLUEPRINT__FOLDER is empty"
lockfile_print_warning
return 1
fi
if [ ! -f "$BLUEPRINT__FOLDER/.blueprint/lock" ]; then
touch "$BLUEPRINT__FOLDER/.blueprint/lock" &> "$BLUEPRINT__DEBUG"
if [ -f "$BLUEPRINT__FOLDER/.blueprint/lock" ]; then
PRINT DEBUG "(lock.sh) lockfile created"
return 0
else
PRINT DEBUG "(lock.sh) lockfile creation was attempted, was not successful"
lockfile_print_warning
return 1
fi
else
PRINT DEBUG "(lock.sh) lockfile was already locked"
lockfile_print_warning
return 1
fi
}
lock_remove() {
if [[ $BLUEPRINT__FOLDER == "" ]]; then
PRINT DEBUG "(lock.sh) lockfile could not be unlocked, \$BLUEPRINT__FOLDER is empty"
lockfile_print_warning
return 1
fi
if [ ! -f "$BLUEPRINT__FOLDER/.blueprint/lock" ]; then
PRINT DEBUG "(lock.sh) Lockfile was already unlocked"
lockfile_print_warning
return 1
fi
rm "$BLUEPRINT__FOLDER/.blueprint/lock" &> "$BLUEPRINT__DEBUG"
if [ -f "$BLUEPRINT__FOLDER/.blueprint/lock" ]; then
PRINT DEBUG "(lock.sh) Lockfile unlock attempted, did not succeed"
lockfile_print_warning
return 1
fi
return 0
}
lock_wait() {
if [ -f "$BLUEPRINT__FOLDER/.blueprint/lock" ]; then
PRINT DEBUG "(lock.sh) found lockfile, waiting for file to be removed"
PRINT WARNING "Lockfile found, waiting for file to be unlocked.."
local i
i=1
while [ -f "$BLUEPRINT__FOLDER/.blueprint/lock" ]; do
sleep 5
PRINT DEBUG "(lock.sh) lockfile still persistent ($i tries)"
((i++))
done
fi
}