summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--files/git-fetch-lock.patch59
-rwxr-xr-xtemplates/turris.run1
2 files changed, 60 insertions, 0 deletions
diff --git a/files/git-fetch-lock.patch b/files/git-fetch-lock.patch
new file mode 100644
index 0000000..adeb4c1
--- /dev/null
+++ b/files/git-fetch-lock.patch
@@ -0,0 +1,59 @@
+From f08b9ae86aa612b71512451b9db0c7e729dda58c Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= <cynerd@email.cz>
+Date: Wed, 29 Jul 2020 09:02:08 +0200
+Subject: [PATCH] compile_pkgs: protect repository fetch from local mirror with
+ lock
+
+We have protection for local repository mirror update but we do not have
+it for reading. It can happen that while one instance is updating
+repository the second one is trying to read it. That leads to git
+failing about unexpected references. This adds read protection as well
+as write one for local mirror repositories.
+---
+ compile_pkgs | 14 +++++++++++---
+ 1 file changed, 11 insertions(+), 3 deletions(-)
+
+diff --git a/compile_pkgs b/compile_pkgs
+index 8184e04..2af84b3 100755
+--- a/compile_pkgs
++++ b/compile_pkgs
+@@ -231,6 +231,14 @@ EOF
+ mirror_updated="yes"
+ }
+
++_git_fetch() {
++ if [ -n "$GIT_MIRROR" ] && [ -d "$GIT_MIRROR" ]; then
++ flock --shared "$GIT_MIRROR" -- git fetch "$@"
++ else
++ git fetch "$@"
++ fi
++}
++
+ _checkout_init() {
+ report "Checking out clean OpenWRT repository"
+ update_mirror
+@@ -267,10 +275,10 @@ checkout() {
+ local githash
+ githash="$(echo "$OPENWRT_BRANCH" | sed -n 's|^#||p')"
+ if [ -n "$githash" ]; then
+- git fetch origin
++ _git_fetch origin
+ git checkout -f "$githash"
+ else
+- git fetch ${CLONE_DEEP+--depth 1} origin "$OPENWRT_BRANCH"
++ _git_fetch ${CLONE_DEEP+--depth 1} origin "$OPENWRT_BRANCH"
+ git checkout -f "origin/$OPENWRT_BRANCH"
+ fi
+ _checkout_clean
+@@ -282,7 +290,7 @@ repo_checkout() {
+ report "Starting out $TARGET_BOARD-$PUBLISH_BRANCH!"
+ curl "https://repo.turris.cz/$PUBLISH_BRANCH/$TARGET_BOARD/packages/git-hash" | tail -n +2 | grep -v '^$' | sed 's/^ \* //;s/: /:/' > repo-git-hashes
+ _checkout_init
+- git fetch
++ _git_fetch
+ git checkout -f "$(awk -F : '/^openwrt:/{print $2}' repo-git-hashes)"
+ GIT_HASHES="$(cat repo-git-hashes)"
+ _checkout_clean
+--
+2.27.0
+
diff --git a/templates/turris.run b/templates/turris.run
index 0752be4..6402019 100755
--- a/templates/turris.run
+++ b/templates/turris.run
@@ -29,6 +29,7 @@ else
"$FILES/turris_checkout_repo_branch.sh" "$ANIMAL"
cat feeds.conf
patch -Np1 -r - < "$FILES/openwrt-hash.patch" || true # just ignore if it fails
+ patch -Np1 -r - < "$FILES/git-fetch-lock.patch" || true # just ignore if it fails
)
echo_stage "Prepare SDK"