From 0a432ebb8bc1137d76d297eb68b4daec5364c89e Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Mon, 29 Jul 2013 23:35:31 -0400 Subject: pro-archman: Lock the archive. --- diff --git a/locale/en_US/pro_archman.sh b/locale/en_US/pro_archman.sh index 8636c72..f27cb84 100644 --- a/locale/en_US/pro_archman.sh +++ b/locale/en_US/pro_archman.sh @@ -17,6 +17,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# src/pro-archman.sh +msg_pro_archman_lock_fail='The archive is locked by another process' + # lib/cmd.sh msg_pro_archman_cmd_not_found='Command "%s" not found' msg_pro_archman_cmd_usage='Usage: %s %s %s' diff --git a/src/pro-archman.sh b/src/pro-archman.sh index 1f9628b..8b0719b 100644 --- a/src/pro-archman.sh +++ b/src/pro-archman.sh @@ -36,6 +36,7 @@ conf_incoming_channel= conf_incoming_dir= conf_pool_gc_delay= archive= +lock= # use() must be defined inline so it can be used to load other modules. use() @@ -100,6 +101,14 @@ main() # FIXME: Remove. archive="${opt_base_dir}" + mkdir -p "${opt_base_dir}/.db" + lock="${opt_base_dir}/.db/lock" + if ! (set -C; printf '%d\n' "${$}" >"${lock}") 2>/dev/null; then + printf '%s: Error: ' "${0##*/}" >&2 + printf "$(get_msg 'lock_fail')\n" >&2 + exit 2 + fi + if [ "x${opt_cmd}" != 'x' ]; then run_cmd "${opt_cmd}" "${@}" status=${?} @@ -159,5 +168,8 @@ fini() { update_feeds collect_garbage + + rm -f "${lock}" } + main "${@}" -- cgit v0.9.1