]> git.ipfire.org Git - people/jschlag/pbs.git/commitdiff
Allow checking if a certain file exists in a package
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 22 Oct 2017 11:29:15 +0000 (12:29 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 22 Oct 2017 11:29:15 +0000 (12:29 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/packages.py
src/web/handlers_packages.py

index af2b4108fbace4136f2365fd4e654e067c25b7fb..266383b1f8d0cc04f1a3d1b3b91c3368c38155cb 100644 (file)
@@ -422,6 +422,13 @@ class Package(base.DataObject):
 
                return ret
 
+       def get_file(self, filename):
+               res = self.db.get("SELECT * FROM filelists \
+                       WHERE pkg_id = %s AND name = %s", self.id, filename)
+
+               if res:
+                       return File(self.backend, res)
+
        def add_file(self, name, size, hash_sha512, type, config, mode, user, group, mtime, capabilities):
                # Convert mtime from seconds since epoch to datetime
                mtime = datetime.datetime.utcfromtimestamp(float(mtime))
@@ -430,7 +437,7 @@ class Package(base.DataObject):
                        \"user\", \"group\", mtime, capabilities) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                        self.id, name, size, hash_sha512, type, config, mode, user, group, mtime, capabilities)
 
-       def get_file(self):
+       def open(self):
                path = os.path.join(PACKAGES_DIR, self.path)
 
                if os.path.exists(path):
index d8f426cb17c013c7640dc5d333174d48ab40f3c6..00b4cd45803a688f44526914f08306a07c2d205b 100644 (file)
@@ -190,11 +190,12 @@ class PackageFileDownloadHandler(BaseHandler):
                        raise tornado.web.HTTPError(404, "Package not found: %s" % pkg_uuid)
 
                # Check if the package has got a file with the given name.
-               if not filename in [f.name for f in pkg.filelist]:
+               file = pkg.get_file(filename)
+               if not file:
                        raise tornado.web.HTTPError(404, "Package %s does not contain file %s" % (pkg, filename))
 
                # Open the package in the filesystem.
-               pkg_file = pkg.get_file()
+               pkg_file = pkg.open()
                if not pkg_file:
                        raise tornado.web.HTTPError(404, "Could not open package %s" % pkg.path)