From: Michael Tremer Date: Sun, 22 Oct 2017 11:29:15 +0000 (+0100) Subject: Allow checking if a certain file exists in a package X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6a6aaccd86554bb10d37965d7ceaa1f2d441f405;p=people%2Fjschlag%2Fpbs.git Allow checking if a certain file exists in a package Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/packages.py b/src/buildservice/packages.py index af2b410..266383b 100644 --- a/src/buildservice/packages.py +++ b/src/buildservice/packages.py @@ -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): diff --git a/src/web/handlers_packages.py b/src/web/handlers_packages.py index d8f426c..00b4cd4 100644 --- a/src/web/handlers_packages.py +++ b/src/web/handlers_packages.py @@ -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)