From: Michael Tremer Date: Tue, 11 Feb 2025 15:39:46 +0000 (+0000) Subject: mirrors: Check if the file exists at all X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=58da71336701e3037790824b45c8651544f74735;p=pbs.git mirrors: Check if the file exists at all We should not query any mirrors for files that even we don't have ourselves. Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/__init__.py b/src/buildservice/__init__.py index fd866512..ee9a2a30 100644 --- a/src/buildservice/__init__.py +++ b/src/buildservice/__init__.py @@ -353,11 +353,15 @@ class Backend(object): ) @run_in_thread - def exists(self, *args, **kwargs): + def exists(self, path): """ Checks whether a file exists """ - return os.path.exists(*args, **kwargs) + # Make the path absolute + if not path.startswith("/"): + path = self.path(path) + + return os.path.exists(path) @run_in_thread def makedirs(self, path, **kwargs): diff --git a/src/web/mirrors.py b/src/web/mirrors.py index 4a334bb1..7a533e1a 100644 --- a/src/web/mirrors.py +++ b/src/web/mirrors.py @@ -135,6 +135,10 @@ class DownloadsHandler(base.BaseHandler): """ @base.ratelimit(limit=100, minutes=60, key="downloads") async def get(self, path): + # Check if the file exists + if not await self.backend.exists(path): + raise tornado.web.HTTPError(404) + # Fetch all mirrors for this client mirrors = await self.backend.mirrors.get_mirrors_for_address(self.current_address)