misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux
Rust bittorrent-clientdebriddownload-acceleratordownload-managerdownloadmanagereguifile-downloadergallery-dlidmidm-alternativeinternet-download-managerm3u8-downloadermagnetplaylist-downloaderreal-debridrusttorrent-clientvideo-downloaderyoutube-downloaderyt-dlp
Release: the build's helper downloads sign in and try again (#315)
Ahmed Nefzaoui949e55e84d36
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 39bfdd7b..7f74813b 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -101,6 +101,8 @@ jobs:# download includes the .pdb files themselves).- name: Symbolsshell: pwsh+ env:+ GH_TOKEN: ${{ github.token }} # downloads the build's helpers signed in (fetch_release.py)run: |$v = [regex]::Match((Get-Content Cargo.toml -Raw), '(?m)^version\s*=\s*"([^"]+)"').Groups[1].Value$exes = "misterdownloadmanager", "misterdownloadmanager-nmhost", "misterdownloadmanager-cli", "misterdownloadmanager-mcp" |@@ -223,6 +225,8 @@ jobs:libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev rpm python3-pil zsync- name: AppImage, tar.gz, .deb, .rpm+ env:+ GH_TOKEN: ${{ github.token }} # downloads the build's helpers signed in (fetch_release.py)run: bash tools/installer/build-linux.sh- uses: actions/upload-artifact@v4@@ -254,6 +258,8 @@ jobs:restore-keys: release-${{ runner.os }}-cargo-- name: Apple Silicon and Intel .dmg+ env:+ GH_TOKEN: ${{ github.token }} # downloads the build's helpers signed in (fetch_release.py)run: bash tools/installer/build-macos.sh- uses: actions/upload-artifact@v4diff --git a/tools/installer/build-linux.sh b/tools/installer/build-linux.shindex 2971462d..c0d437d4 100755--- a/tools/installer/build-linux.sh+++ b/tools/installer/build-linux.sh@@ -7,7 +7,7 @@# MisterDownloadManager-<version>-linux-x86_64.rpm Fedora, RHEL, openSUSE# Update now (crates/tools/src/update.rs), the website (tools/website/build.py) and the docs# look for these names, and still for the "-experimental" ones of older releases.-# Needs: cargo, pwsh (the extension), python3 with Pillow (the icon), dpkg-deb, rpmbuild, curl (appimagetool is fetched),+# Needs: cargo, pwsh (the extension), python3 with Pillow (the icon), dpkg-deb, rpmbuild, network access (appimagetool is fetched),# and zsyncmake if the appimagetool fetched doesn't write the .zsync itself.# Build on the oldest Ubuntu you want to support: the programs need its glibc or newer.# tools/installer/build-linux.sh [--no-build]@@ -157,8 +157,7 @@ ln -s usr/bin/misterdownloadmanager "$appdir/AppRun"cp "$tree/usr/share/applications/misterdownloadmanager.desktop" "$appdir/"cp "$tree/usr/share/icons/hicolor/256x256/apps/misterdownloadmanager.png" "$appdir/"tool="$stage/appimagetool"-curl -fsSL -o "$tool" \- https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage+python3 "$root/tools/installer/fetch_release.py" AppImage/appimagetool continuous appimagetool-x86_64.AppImage "$tool"chmod +x "$tool"# Update information (#24): AppImageLauncher, Gear Lever and AppImageUpdate read it from the# AppImage, find the latest release's .zsync and download only the parts that changed. MDM's owndiff --git a/tools/installer/fetch_release.py b/tools/installer/fetch_release.pynew file mode 100644index 00000000..c6aeb458--- /dev/null+++ b/tools/installer/fetch_release.py@@ -0,0 +1,80 @@+"""One file of a GitHub release, for the release builds' helpers (dump_syms, appimagetool).++ python tools/installer/fetch_release.py <owner/repo> <tag> <file name> <output path>++With GH_TOKEN or GITHUB_TOKEN set it signs in and goes through GitHub's API: anonymous downloads+from github.com can fail while signed-in ones work. Without a token it uses the public address.+A server error or a dropped connection is tried again for several minutes.+"""+import json+import os+import sys+import time+import urllib.error+import urllib.request++# Seconds to wait before each new try: about seven minutes in all.+WAITS = (5, 15, 30, 60, 90, 90, 120)+UA = "mdm-release-build"+++class NoRedirect(urllib.request.HTTPRedirectHandler):+ """Hands a redirect back, so the token isn't sent on to the storage server."""++ def redirect_request(self, *args, **kwargs):+ return None+++def _get(url, token, accept):+ headers = {"User-Agent": UA, "Accept": accept}+ if token:+ headers["Authorization"] = f"Bearer {token}"+ headers["X-GitHub-Api-Version"] = "2022-11-28"+ opener = urllib.request.build_opener(NoRedirect)+ try:+ with opener.open(urllib.request.Request(url, headers=headers), timeout=120) as r:+ return r.read()+ except urllib.error.HTTPError as e:+ if e.code not in (301, 302, 303, 307, 308):+ raise+ target = e.headers["Location"]+ req = urllib.request.Request(target, headers={"User-Agent": UA})+ with urllib.request.urlopen(req, timeout=300) as r:+ return r.read()+++def _once(repo, tag, name, token):+ if not token:+ url = f"https://github.com/{repo}/releases/download/{tag}/{name}"+ return _get(url, None, "application/octet-stream")+ api = f"https://api.github.com/repos/{repo}/releases/tags/{tag}"+ release = json.loads(_get(api, token, "application/vnd.github+json"))+ asset = next((a for a in release["assets"] if a["name"] == name), None)+ if asset is None:+ sys.exit(f"{repo} {tag} has no file named {name}")+ return _get(asset["url"], token, "application/octet-stream")+++def fetch(repo, tag, name):+ """The file's bytes; exits when every try failed."""+ token = os.environ.get("GH_TOKEN") or os.environ.get("GITHUB_TOKEN")+ for wait in (*WAITS, None):+ try:+ return _once(repo, tag, name, token)+ except urllib.error.HTTPError as e:+ if e.code < 500 and e.code != 429:+ sys.exit(f"{name}: HTTP {e.code}")+ problem = f"HTTP {e.code}"+ except (urllib.error.URLError, TimeoutError, ConnectionError) as e:+ problem = str(e)+ if wait is None:+ sys.exit(f"{name}: gave up: {problem}")+ print(f"{name}: {problem}; trying again in {wait} s", flush=True)+ time.sleep(wait)+++if __name__ == "__main__":+ if len(sys.argv) != 5:+ sys.exit(__doc__)+ with open(sys.argv[4], "wb") as f:+ f.write(fetch(sys.argv[1], sys.argv[2], sys.argv[3]))diff --git a/tools/installer/symbols.py b/tools/installer/symbols.pyindex bcdfc1eb..d98d63d7 100644--- a/tools/installer/symbols.py+++ b/tools/installer/symbols.py@@ -19,11 +19,12 @@ import subprocessimport sysimport tarfileimport tempfile-import urllib.requestimport zipfile+sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))+from fetch_release import fetch # noqa: E402 (beside this file: signs in, tries again)+DUMP_SYMS = "v2.3.9"-BASE = f"https://github.com/mozilla/dump_syms/releases/download/{DUMP_SYMS}/"def fetch_dump_syms(work):@@ -34,8 +35,8 @@ def fetch_dump_syms(work):else "dump_syms-x86_64-apple-darwin.tar.xz")else:name = "dump_syms-x86_64-unknown-linux-gnu.tar.xz"- data = urllib.request.urlopen(BASE + name).read()- want = urllib.request.urlopen(BASE + name + ".sha256").read().decode().split()[0]+ data = fetch("mozilla/dump_syms", DUMP_SYMS, name)+ want = fetch("mozilla/dump_syms", DUMP_SYMS, name + ".sha256").decode().split()[0]got = hashlib.sha256(data).hexdigest()if got != want:sys.exit(f"dump_syms checksum mismatch: {got} != {want}")