Skip to content
Snippets Groups Projects
Verified Commit a621a7d7 authored by Karel Koci's avatar Karel Koci :metal: Committed by Karel Koci
Browse files

compile_pkgs: use flock to not colide in git mirrors

This locks git mirror directory when we are updating mirrors. This
should solve race condition with multiple builds failing to update
mirrors and failing that way completely.

Only update is protected. The expectation is that initialization is
happenning only once and is protected by non-existence of directory. If
there is going to be problem with initialization as well then we can add
locking as well.
parent be49424d
No related branches found
No related tags found
1 merge request!113compile_pkgs: use flock to not colide in git mirrors
......@@ -215,30 +215,31 @@ configure() {
available_commands+=( ["update_mirror"]="Updates all local mirrors" )
update_mirror() {
[ -n "$GIT_MIRROR" ] || return 0
[ -d "$GIT_MIRROR" ] || return 0
[ -z "$mirror_updated" ] || return 0
_report "Updating local mirrors"
mkdir -p "$GIT_MIRROR"
pushd "$GIT_MIRROR"
if [ ! -d openwrt ]; then
git clone --mirror "$OPENWRT_URL" openwrt
fi
OPENWRT_URL="$GIT_MIRROR/openwrt"
for mirror in ./*; do
cd "$mirror" || continue
if ! git remote update --prune; then
sleep $(( 1 + RANDOM % 30 ))
flock --exclusive "$GIT_MIRROR" "$SHELL" -s "$GIT_MIRROR" <<"EOF"
cd "$1"
for mirror in ./*; do
[ -d "$mirror" ] || continue
cd "$mirror"
git remote update --prune
fi
cd "$GIT_MIRROR"
done
popd
cd "$1"
done
EOF
mirror_updated="yes"
}
_checkout_init() {
_report "Checking out clean OpenWRT repository"
update_mirror
if [ -n "$GIT_MIRROR" ]; then
mkdir -p "$GIT_MIRROR"
[ -d "$GIT_MIRROR/openwrt" ] || \
git clone --mirror "$OPENWRT_URL" "$GIT_MIRROR/openwrt"
OPENWRT_URL="$GIT_MIRROR/openwrt"
fi
rm -rf .git
git init
git remote add origin "$OPENWRT_URL"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment