summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2013-07-29 23:35:31 (EDT)
committer P. J. McDermott <pjm@nac.net>2013-07-29 23:35:31 (EDT)
commit0a432ebb8bc1137d76d297eb68b4daec5364c89e (patch)
treede87d63931796a41e105273ae97ba3254f564469
parentfb4283933ca23b47cb27b8fa51b1c1431b6df7dd (diff)
pro-archman: Lock the archive.
-rw-r--r--locale/en_US/pro_archman.sh3
-rw-r--r--src/pro-archman.sh12
2 files changed, 15 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>.
+# 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 "${@}"