Skip to content

Commit

Permalink
small update to the flock locking behavior for git status updating
Browse files Browse the repository at this point in the history
  • Loading branch information
k-rister committed Feb 5, 2024
1 parent 8c8b52f commit 922bd05
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 6 additions & 2 deletions bin/_git-fetch
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ touch "${PROCESS_LOCK_FILE}"
chmod 666 "${PROCESS_LOCK_FILE}"

if [ -e "${UPDATE_STATUS_FILE}" ]; then
read FETCH_TIMESTAMP OTHER < "${UPDATE_STATUS_FILE}"
{
flock --timeout 2 --shared 9 || exit_error "Failed to shared acquire ${UPDATE_STATUS_LOCK_FILE} in _git-fetch"

read FETCH_TIMESTAMP OTHER < "${UPDATE_STATUS_FILE}"
} 9<"${UPDATE_STATUS_LOCK_FILE}"

CURRENT_TIMESTAMP=$(date +%s)

Expand Down Expand Up @@ -72,7 +76,7 @@ touch "${PROCESS_LOCK_FILE}"

CURRENT_TIMESTAMP=$(date +%s)
{
flock --timeout 10 --exclusive 9 || exit 0
flock --timeout 10 --exclusive 9 || exit_error "Failed to exclusively acquire ${UPDATE_STATUS_LOCK_FILE}"

echo "${CURRENT_TIMESTAMP} ${UPDATE_COUNT}" > "${UPDATE_STATUS_FILE}"
} 9<"${UPDATE_STATUS_LOCK_FILE}"
Expand Down
11 changes: 6 additions & 5 deletions bin/crucible
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ if [ "${1}" != "update" ]; then
${CRUCIBLE_HOME}/bin/_git-fetch &
if [ -e "${UPDATE_STATUS_FILE}" ]; then
{
flock --timeout 2 --shared 9 || exit 0
flock --timeout 2 --shared 9 || exit_error "Failed to shared acquire ${UPDATE_STATUS_LOCK_FILE}"

read OTHER UPDATE_COUNT < "${UPDATE_STATUS_FILE}"
if [ "${UPDATE_COUNT}" != "0" ]; then
echo "*** NOTICE: Crucible is at least ${UPDATE_COUNT} commits behind. See 'crucible repo info' for details. ***"
echo
fi
} 9<"${UPDATE_STATUS_LOCK_FILE}"

if [ "${UPDATE_COUNT}" != "0" ]; then
echo "*** NOTICE: Crucible is at least ${UPDATE_COUNT} commits behind. See 'crucible repo info' for details. ***"
echo
fi
fi
fi

Expand Down

0 comments on commit 922bd05

Please sign in to comment.