]> git.ipfire.org Git - pbs.git/commitdiff
mirrors: Check if the file exists at all
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 11 Feb 2025 15:39:46 +0000 (15:39 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 11 Feb 2025 15:39:46 +0000 (15:39 +0000)
We should not query any mirrors for files that even we don't have
ourselves.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/__init__.py
src/web/mirrors.py

index fd866512234df9f7ff8460fe3825a1d870b92086..ee9a2a30427130bf8b0588a23da255e6fc1b7492 100644 (file)
@@ -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):
index 4a334bb1f2ad017327d9fc9eba23b36aaf615506..7a533e1aa904b0812a2e8b0aeac00605a94e7a0f 100644 (file)
@@ -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)