Skip to content
This repository was archived by the owner on Jul 2, 2026. It is now read-only.

Commit dfd8a14

Browse files
committed
fix(pmd): use atomic rename to avoid concurrent extraction conflicts
Extract to a temporary directory first, then atomically move into place. This prevents parallel prek processes from contending over partial extractions and hitting unzip errors when the destination already exists.
1 parent d662240 commit dfd8a14

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

hooks/pmd/run.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,15 @@ if [[ ! -x "${pmd_launcher}" ]]; then
3333
printf 'pmd: `unzip` not available; install it to extract the pmd distribution.\n' >&2
3434
exit 1
3535
fi
36-
mkdir -p "${extract_dir}"
37-
unzip -q -o -d "${extract_dir}" "${archive_path}"
38-
chmod +x "${pmd_launcher}"
36+
# Extract to a temporary directory first, then move atomically.
37+
# This prevents concurrent extraction processes from conflicting.
38+
temp_extract_dir="${extract_dir}.$$-${RANDOM}"
39+
mkdir -p "${temp_extract_dir}"
40+
unzip -q -d "${temp_extract_dir}" "${archive_path}"
41+
chmod +x "${temp_extract_dir}/pmd-bin-${VERSION}/bin/pmd"
42+
# Atomic rename (only one process will succeed).
43+
mkdir -p "$(dirname "${extract_dir}")"
44+
mv -f "${temp_extract_dir}" "${extract_dir}" || rm -rf "${temp_extract_dir}" 2>/dev/null || true
3945
fi
4046

4147
# Make the launcher pick up our verified JDK.

0 commit comments

Comments
 (0)