Skip to content

Commit 2bb1490

Browse files
committed
_ensure_aur_repo: use a lockfile to avoid concurrent access
1 parent 72e1ea3 commit 2bb1490

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

lilac2/api.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import httpx
2121

22-
from .vendor.myutils import at_dir
22+
from .vendor.myutils import at_dir, file_lock
2323
from .vendor.htmlutils import parse_document_from_httpx
2424

2525
from .cmd import git_pull, git_push, UNTRUSTED_PREFIX
@@ -364,16 +364,18 @@ def _aur_exists(pkgbase: str) -> bool:
364364
return r.status_code != 404
365365

366366
def _ensure_aur_repo(pkgbase: str) -> Path:
367-
aurpath = const.AUR_REPO_DIR / pkgbase
368-
if not aurpath.is_dir():
369-
logger.info('cloning AUR repo: %s', aurpath)
370-
with at_dir(const.AUR_REPO_DIR):
371-
_run_cmd(['git', 'clone', f'[email protected]:{pkgbase}.git'])
372-
else:
373-
with at_dir(aurpath):
374-
# reset everything, dropping local commits
375-
_run_cmd(['git', 'reset', '--hard', 'origin/master'])
376-
git_pull()
367+
lockfile = const.AUR_REPO_DIR / (pkgbase + '.lock')
368+
with file_lock(lockfile):
369+
aurpath = const.AUR_REPO_DIR / pkgbase
370+
if not aurpath.is_dir():
371+
logger.info('cloning AUR repo: %s', aurpath)
372+
with at_dir(const.AUR_REPO_DIR):
373+
_run_cmd(['git', 'clone', f'[email protected]:{pkgbase}.git'])
374+
else:
375+
with at_dir(aurpath):
376+
# reset everything, dropping local commits
377+
_run_cmd(['git', 'reset', '--hard', 'origin/master'])
378+
git_pull()
377379

378380
return aurpath
379381

0 commit comments

Comments
 (0)