From: Hans-Christoph Steiner Date: Wed, 19 Jul 2017 10:59:20 +0000 (+0200) Subject: server: include gitlab raw URLs as git mirrors X-Git-Tag: 0.8~9^2~10 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=93caf27319da76626afef357b57c9e9fc7fd4622;p=fdroidserver.git server: include gitlab raw URLs as git mirrors gitlab serves raw files from a CDN, so its appropriate to use the raw URL. @pserwylo @grote and I discussed it and found a reference, but I can't find that reference now. Since the client will try the next mirror if one fails, it makes sense to include both the gitlab raw and gitlab pages URLs to the mirror. The gitlab pages deploy process is still a bit flaky anyway. --- diff --git a/fdroidserver/index.py b/fdroidserver/index.py index 6843f520..86b4bb08 100644 --- a/fdroidserver/index.py +++ b/fdroidserver/index.py @@ -112,9 +112,8 @@ def make(apps, sortedids, apks, repodir, archive): else: mirrors.append(urllib.parse.urljoin(mirror + '/', urlbasepath)) for mirror in common.config.get('servergitmirrors', []): - mirror = get_mirror_service_url(mirror) - if mirror: - mirrors.append(mirror + '/' + repodir) + for url in get_mirror_service_urls(mirror): + mirrors.append(url + '/' + repodir) if mirrorcheckfailed: raise FDroidException("Malformed repository mirrors.") if mirrors: @@ -525,14 +524,15 @@ def extract_pubkey(): return hexlify(pubkey), repo_pubkey_fingerprint -def get_mirror_service_url(url): - '''Get direct URL from git service for use by fdroidclient +def get_mirror_service_urls(url): + '''Get direct URLs from git service for use by fdroidclient Via 'servergitmirrors', fdroidserver can create and push a mirror to certain well known git services like gitlab or github. This will always use the 'master' branch since that is the default - branch in git. - + branch in git. The files are then accessible via alternate URLs, + where they are served in their raw format via a CDN rather than + from git. ''' if url.startswith('git@'): @@ -549,18 +549,23 @@ def get_mirror_service_url(url): branch = "master" folder = "fdroid" + urls = [] if hostname == "github.com": - # Github-like RAW segments "https://raw.githubusercontent.com/user/repo/master/fdroid" + # Github-like RAW segments "https://raw.githubusercontent.com/user/repo/branch/folder" segments[2] = "raw.githubusercontent.com" segments.extend([branch, folder]) + urls.append('/'.join(segments)) elif hostname == "gitlab.com": - # Gitlab-like Pages segments "https://user.gitlab.com/repo/fdroid" - gitlab_url = ["https:", "", user + ".gitlab.io", repo, folder] - segments = gitlab_url - else: - return None + # Gitlab Raw "https://gitlab.com/user/repo/raw/branch/folder" + gitlab_raw = segments + ['raw', branch, folder] + urls.append('/'.join(gitlab_raw)) + # Gitlab-like Pages segments "https://user.gitlab.io/repo/folder" + gitlab_pages = ["https:", "", user + ".gitlab.io", repo, folder] + urls.append('/'.join(gitlab_pages)) + return urls + + return urls - return '/'.join(segments) def download_repo_index(url_str, etag=None, verify_fingerprint=True):