summaryrefslogtreecommitdiff
path: root/functions
diff options
context:
space:
mode:
Diffstat (limited to 'functions')
-rwxr-xr-xfunctions/lockfile.sh42
1 files changed, 20 insertions, 22 deletions
diff --git a/functions/lockfile.sh b/functions/lockfile.sh
index cf7e22d5f..b467d25f3 100755
--- a/functions/lockfile.sh
+++ b/functions/lockfile.sh
@@ -9,40 +9,38 @@
## under certain conditions; see COPYING for details.
-Check_lockfile ()
+Acquire_lockfile ()
{
- FILE="${1}"
+ local FILE="${1:-.lock}"
+ Check_lockfile "${FILE}"
+ Create_lockfile "${FILE}"
+}
- if [ -z "${FILE}" ]
- then
- FILE=".build/lock"
- fi
+Check_lockfile ()
+{
+ local FILE="${1}"
- # Checking lock file
- if [ -f "${FILE}" ]
- then
- Echo_error "${PROGRAM} locked"
+ if [ -f "${FILE}" ]; then
+ Echo_error "${PROGRAM} already locked"
exit 1
fi
}
Create_lockfile ()
{
- FILE="${1}"
-
- if [ -z "${FILE}" ]
- then
- FILE=".build/lock"
- fi
+ local FILE="${1}"
- DIRECTORY="$(dirname ${FILE})"
-
- # Creating lock directory
- mkdir -p "${DIRECTORY}"
-
- # Creating lock trap
+ # Create lock trap
+ # This automatically removes the lock file in certain conditions
trap 'ret=${?}; '"rm -f \"${FILE}\";"' exit ${ret}' EXIT HUP INT QUIT TERM
# Creating lock file
touch "${FILE}"
}
+
+Remove_lockfile ()
+{
+ local FILE="${1:-.lock}"
+
+ rm -f "${FILE}"
+}