Skip to content

Commit 72e1ea3

Browse files
committed
api: fetch AUR files via git
as cgit is protected by Anubis fixes #227.
1 parent 6d7de34 commit 72e1ea3

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

lilac2/api.py

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,7 @@ def _aur_exists(pkgbase: str) -> bool:
363363
r.raise_for_status()
364364
return r.status_code != 404
365365

366-
def _update_aur_repo_real(pkgbase: str) -> None:
367-
if not _aur_exists(pkgbase):
368-
raise LookupError('AUR package not exists, not updating!', pkgbase)
369-
366+
def _ensure_aur_repo(pkgbase: str) -> Path:
370367
aurpath = const.AUR_REPO_DIR / pkgbase
371368
if not aurpath.is_dir():
372369
logger.info('cloning AUR repo: %s', aurpath)
@@ -378,6 +375,14 @@ def _update_aur_repo_real(pkgbase: str) -> None:
378375
_run_cmd(['git', 'reset', '--hard', 'origin/master'])
379376
git_pull()
380377

378+
return aurpath
379+
380+
def _update_aur_repo_real(pkgbase: str) -> None:
381+
if not _aur_exists(pkgbase):
382+
raise LookupError('AUR package not exists, not updating!', pkgbase)
383+
384+
aurpath = _ensure_aur_repo(pkgbase)
385+
381386
with at_dir(aurpath):
382387
oldfiles = set(_run_cmd(['git', 'ls-files']).splitlines())
383388

@@ -468,33 +473,17 @@ def clean_directory() -> List[str]:
468473
os.unlink(f)
469474
return ret
470475

471-
def _try_aur_url(name: str) -> bytes:
472-
aur4url = 'https://aur.archlinux.org/cgit/aur.git/snapshot/{name}.tar.gz'
473-
templates = [aur4url]
474-
urls = [url.format(first_two=name[:2], name=name) for url in templates]
475-
for url in urls:
476-
for _ in range(2):
477-
try:
478-
response = s.get(url)
479-
except httpx.ReadTimeout:
480-
logger.warning('AUR download timed out.')
481-
continue
482-
483-
if response.status_code == 200:
484-
logger.debug("downloaded aur tarball '%s' from url '%s'", name, url)
485-
return response.content
486-
elif response.status_code >= 500:
487-
logger.warning('AUR download failed.')
488-
else:
489-
break
490-
logger.error("failed to find aur url for '%s'", name)
491-
raise AurDownloadError(name)
476+
def _get_aur_tarball(name: str) -> bytes:
477+
aurpath = _ensure_aur_repo(name)
478+
return subprocess.check_output([
479+
'git', 'archive', f'--prefix={name}/', 'HEAD',
480+
], cwd=aurpath)
492481

493482
def _download_aur_pkgbuild(name: str) -> List[str]:
494-
content = io.BytesIO(_try_aur_url(name))
483+
content = io.BytesIO(_get_aur_tarball(name))
495484
files = []
496485
with tarfile.open(
497-
name=name+".tar.gz", mode="r:gz", fileobj=content
486+
name=name+".tar", mode="r:", fileobj=content
498487
) as tarf:
499488
for tarinfo in tarf:
500489
try:
@@ -553,7 +542,10 @@ def aur_pre_build(
553542

554543
pkgver, pkgrel = get_pkgver_and_pkgrel()
555544
_g.aur_pre_files = clean_directory()
556-
_g.aur_building_files = _download_aur_pkgbuild(name)
545+
try:
546+
_g.aur_building_files = _download_aur_pkgbuild(name)
547+
except Exception:
548+
raise AurDownloadError(name)
557549

558550
aur_pkgver, aur_pkgrel = get_pkgver_and_pkgrel()
559551
if pkgver and pkgver == aur_pkgver:

0 commit comments

Comments
 (0)