Skip to content

Commit acf4165

Browse files
committed
switch back to pid file with atomic ln
1 parent bd1d09b commit acf4165

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

scripts/build-sentry-cocoa.sh

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,24 @@ pushd "$(dirname "$0")" >/dev/null
55
cd ../modules/sentry-cocoa
66

77
mkdir -p Carthage
8-
LOCK_DIR="$PWD/Carthage/.build.lock"
9-
trap 'if [[ "$(cat "$LOCK_DIR/pid" 2>/dev/null)" == "$$" ]]; then rm -rf "$LOCK_DIR"; fi' EXIT
8+
PID_FILE="$PWD/Carthage/.build.pid"
9+
trap 'if [[ "$(cat "$PID_FILE" 2>/dev/null)" == "$$" ]]; then rm -f "$PID_FILE"; fi' EXIT
1010

1111
# Serialize concurrent invocations; parallel xcodebuilds race on DerivedData.
12-
while ! mkdir "$LOCK_DIR" 2>/dev/null; do
13-
build_pid=$(cat "$LOCK_DIR/pid" 2>/dev/null || true)
12+
TMP_FILE=$(mktemp "$PID_FILE.tmp.XXXXXX")
13+
echo $$ > "$TMP_FILE"
14+
while ! ln "$TMP_FILE" "$PID_FILE" 2>/dev/null; do
15+
build_pid=$(cat "$PID_FILE" 2>/dev/null || true)
1416
if [[ -n "$build_pid" ]] && ! kill -0 "$build_pid" 2>/dev/null; then
1517
echo "Previous build did not complete (pid $build_pid); cleaning up and retrying" >&2
16-
# Atomically claim the stale dir via rename
17-
if mv "$LOCK_DIR" "$LOCK_DIR.stale.$$" 2>/dev/null; then
18-
rm -rf "$LOCK_DIR.stale.$$"
18+
if mv "$PID_FILE" "$PID_FILE.stale.$$" 2>/dev/null; then
19+
rm -f "$PID_FILE.stale.$$"
1920
fi
2021
continue
2122
fi
2223
sleep 2
2324
done
24-
echo $$ > "$LOCK_DIR/pid"
25+
rm -f "$TMP_FILE"
2526

2627
current_sha=$(git rev-parse HEAD)
2728
if [[ -f Carthage/.built-from-sha ]] && [[ "$(cat Carthage/.built-from-sha)" == "$current_sha" ]]; then

0 commit comments

Comments
 (0)