From: Michael Tremer Date: Fri, 15 Jul 2022 16:55:30 +0000 (+0000) Subject: packages: Import filelists X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee22e560727af357db0fe2edf2e470ec1deebc20;p=pbs.git packages: Import filelists Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/packages.py b/src/buildservice/packages.py index 3d964a6f..0986f238 100644 --- a/src/buildservice/packages.py +++ b/src/buildservice/packages.py @@ -6,9 +6,12 @@ import logging import mimetypes import os import shutil -import urllib.parse import pakfire +from pakfire.constants import ( + PAKFIRE_DIGEST_SHA512, + PAKFIRE_DIGEST_SHA256, +) from . import base from . import database @@ -143,11 +146,8 @@ class Packages(base.Object): package.hexdigest_sha512, ) - # XXX Import filelist - for file in package.filelist: - print(file) - - print(pkg) + # Import filelist + pkg._import_filelist(archive.filelist) # Import package data pkg._import_archive(archive) @@ -375,9 +375,51 @@ class Package(base.DataObject): # Copy the file shutil.copyfile(archive.path, path) + # XXX use async copy here + # Store the path self._set_attribute("path", path) + def _import_filelist(self, filelist): + log.debug("Importing filelist for %s" % self) + + # XXX capabilities + + self.db.executemany(""" + INSERT INTO + filelists + ( + pkg_id, + path, + size, + type, + mode, + "user", + "group", + ctime, + mtime, + digest_sha512, + digest_sha256 + ) + VALUES + ( + %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s + )""", + (( + self.id, + file.path, + file.size, + file.type, + file.mode, + file.user, + file.group, + file.ctime, + file.mtime, + file.digest(PAKFIRE_DIGEST_SHA512), + file.digest(PAKFIRE_DIGEST_SHA256), + ) for file in filelist), + ) + @lazy_property def builds(self): builds = self.backend.builds._get_builds(""" @@ -405,7 +447,7 @@ class Package(base.DataObject): @lazy_property def filelist(self): res = self.db.query("SELECT * FROM filelists \ - WHERE pkg_id = %s ORDER BY name", self.id) + WHERE pkg_id = %s ORDER BY path", self.id) ret = [] for row in res: @@ -416,19 +458,11 @@ class Package(base.DataObject): def get_file(self, filename): res = self.db.get("SELECT * FROM filelists \ - WHERE pkg_id = %s AND name = %s", self.id, filename) + WHERE pkg_id = %s AND path = %s", self.id, filename) if res: return File(self.backend, self, 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)) - - self.db.execute("INSERT INTO filelists(pkg_id, name, size, hash_sha512, type, config, mode, \ - \"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) - async def open(self): """ Opens the package archive and returns a handle @@ -474,16 +508,12 @@ class File(base.Object): @property def name(self): - return self.data.name + return self.data.path @property def size(self): return self.data.size - @property - def hash_sha512(self): - return self.data.hash_sha512 - @property def type(self): return self.data.type @@ -504,6 +534,10 @@ class File(base.Object): def group(self): return self.data.group + @property + def ctime(self): + return self.data.ctime + @property def mtime(self): return self.data.mtime @@ -512,6 +546,18 @@ class File(base.Object): def capabilities(self): return self.data.capabilities + # Digest SHA512 + + @property + def digest_sha512(self): + return self.data.digest_sha512 + + # Digest SHA256 + + @property + def digest_sha256(self): + return self.data.digest_sha256 + def is_downloadable(self): """ Returns True if this file is downloadable