mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-28 20:38:52 -06:00
refactor: route network access through upstream
Branch heads (scrapers, FBNeo import, data directories) resolve through core.upstream.resolve_head, with cache_dir=None to keep nothing under .cache/upstream. Streaming downloads (large files, external pack files, data directory archives, scraper downloads, standalone probe) go through one core.upstream.download: scratch then rename, size cap, retries of a cut stream, a 5xx or a rate limit. The shared rate limit wait reads GoatCounter's X-Rate-Limit-Reset, so site insights, download.py, indexnow and the contributor list use the same retrying client. list_gitlinks raises TruncatedListingError on a partial tree, read from one tree walk shared with list_tree (Forgejo paging included). The Recalbox configs/ listing is paged with the shared page cap.
This commit is contained in:
1 parent
526d7f09c7
commit
8a8fa71fbc
25 files changed
+708
-266
No files matched your search
@@ -720,6 +720,36 @@ class AProgressBarOnlyOnATerminal(unittest.TestCase):
|
||||
self.assertNotIn("\r", out.getvalue())
|
||||
self.assertEqual(out.getvalue().count("\n"), 1)
|
||||
|
||||
def test_a_cut_stream_is_fetched_again_from_the_start(self):
|
||||
"""One reset midway through a 2 GiB part failed the whole download."""
|
||||
import http.client
|
||||
|
||||
from core import upstream
|
||||
|
||||
class Body(io.BytesIO):
|
||||
headers = {"Content-Length": "6"}
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, *exc):
|
||||
return False
|
||||
|
||||
class Cut(Body):
|
||||
def read(self, size: int = -1) -> bytes:
|
||||
raise http.client.IncompleteRead(b"pa")
|
||||
|
||||
answers = [Cut(b""), Body(b"packed")]
|
||||
with tempfile.TemporaryDirectory() as directory, \
|
||||
mock.patch.object(download.urllib.request, "urlopen",
|
||||
lambda *a, **k: answers.pop(0)), \
|
||||
mock.patch.object(upstream, "_sleep", lambda _s: None), \
|
||||
contextlib.redirect_stdout(io.StringIO()):
|
||||
target = Path(directory) / "a.zip"
|
||||
download.download_file("https://example.com/a.zip", target, 6, "a.zip ")
|
||||
self.assertEqual(target.read_bytes(), b"packed")
|
||||
self.assertEqual(answers, [])
|
||||
|
||||
|
||||
class TheShellDownloaderSendsTheToken(unittest.TestCase):
|
||||
"""download.py sent GITHUB_TOKEN to the API and download.sh did not, so
|
||||
|
||||
Reference in new issue
Block a user