From 56f1986cab1048a25325e131811d6d55991c8ebe Mon Sep 17 00:00:00 2001 From: Aki Kareha Date: Sat, 22 Feb 2025 13:01:06 +0900 Subject: [PATCH] use locking by mkdir --- update | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/update b/update index 000a511..fc85b96 100755 --- a/update +++ b/update @@ -4,6 +4,8 @@ CSV_URL="https://www8.cao.go.jp/chosei/shukujitsu/syukujitsu.csv" # Internal configuration settings +LOCK_DIR="lock" + TMP_CSV_FILE="holidays-jp-tmp.csv" RAW_CSV_FILE="holidays-jp-raw.csv" CSV_FILE="holidays-jp.csv" @@ -21,6 +23,12 @@ if ! command -v nkf >/dev/null; then exit $EXIT_FAILURE fi +# Acquire the lock or exit +if ! mkdir "$LOCK_DIR" 2>/dev/null; then + echo "Another process is holding the lock. Exiting." + exit $EXIT_FAILURE +fi + # Run curl -sS -L -o $TMP_CSV_FILE $CSV_URL if ! diff -q $RAW_CSV_FILE $TMP_CSV_FILE >/dev/null 2>&1; then @@ -30,5 +38,8 @@ else rm $TMP_CSV_FILE fi +# Release the lock +rmdir "$LOCK_DIR" + # Exit exit $EXIT_SUCCESS