fix: address whole-branch review findings for update-swarm
- versions: require entire normalized string to be numeric so dates and hotfix suffixes compare as incomparable instead of eq/gt - hosts: exact host or dot-suffix match rejects lookalikes like notmediafire.com and evilmega.nz; GitHub stays exact-set - census: lazy extractor loop so a later OSError no longer discards an earlier sidecar changelog hit - jobs: watchlist parses only table rows whose vault-note cell is a bare wikilink (skips parenthetical related/complete notes); wanted also matches bold names in Wanted.md tables with Pokemon prefix stripped and casefolded - cli: validate-scouts and judge raise SystemExit when jobs.json has jobs but scouts/ has zero valid files - fetch: download forwards timeout=60 to urlopen and writes to a .part file then os.replace, removing the partial on any failure
This commit is contained in:
1 parent
37ebc97b51
commit
cb294f72a0
16 files changed
+234
-48
No files matched your search
@@ -17,8 +17,8 @@ def resolve_mediafire(html: str) -> str | None:
|
||||
def _open(url: str, opener=None):
|
||||
req = urllib.request.Request(url, headers={"User-Agent": UA})
|
||||
if opener:
|
||||
return opener(req)
|
||||
return urllib.request.urlopen(req)
|
||||
return opener(req, timeout=60)
|
||||
return urllib.request.urlopen(req, timeout=60)
|
||||
|
||||
def download(url: str, dest_path: str, opener=None) -> dict:
|
||||
host, gate = classify_url(url)
|
||||
@@ -35,16 +35,23 @@ def download(url: str, dest_path: str, opener=None) -> dict:
|
||||
raise ValueError("no mediafire direct link")
|
||||
fetch_url = direct
|
||||
os.makedirs(os.path.dirname(dest_path) or ".", exist_ok=True)
|
||||
part_path = dest_path + ".part"
|
||||
h = hashlib.sha256()
|
||||
size = 0
|
||||
with _open(fetch_url, opener) as resp, open(dest_path, "wb") as out:
|
||||
while True:
|
||||
chunk = resp.read(1024 * 1024)
|
||||
if not chunk:
|
||||
break
|
||||
out.write(chunk)
|
||||
h.update(chunk)
|
||||
size += len(chunk)
|
||||
try:
|
||||
with _open(fetch_url, opener) as resp, open(part_path, "wb") as out:
|
||||
while True:
|
||||
chunk = resp.read(1024 * 1024)
|
||||
if not chunk:
|
||||
break
|
||||
out.write(chunk)
|
||||
h.update(chunk)
|
||||
size += len(chunk)
|
||||
except BaseException:
|
||||
if os.path.exists(part_path):
|
||||
os.remove(part_path)
|
||||
raise
|
||||
os.replace(part_path, dest_path)
|
||||
return {"path": dest_path, "sha256": h.hexdigest(), "size": size, "url": fetch_url}
|
||||
|
||||
def english_mismatch(archive_path: str, expected_version: str) -> bool:
|
||||
|
||||
Reference in new issue
Block a user