PR#4113: cg import updates

Merges #4113
https://pagure.io/koji/pull-request/4113

Fixes: #1402
https://pagure.io/koji/issue/1402
[RFE] Restrict CG imports by build type

Fixes: #4119
https://pagure.io/koji/issue/4119
Support subdirs for cg imports
This commit is contained in:
Tomas Kopecek 2024-07-03 13:17:51 +02:00
commit 4abd33640e
2 changed files with 17 additions and 4 deletions

View file

@ -138,6 +138,9 @@ Each map in the output list contains the following entries:
- buildroot\_id: The id of the buildroot used to create this file. Must
match an entry in the buildroots list.
- filename: The name of the file.
- relpath: relative path for the uploaded file. I.e. the file was uploaded to
$upload_dir/$relpath/$filename
- subdir: subdir for final location. Only valid for logs and non-legacy btypes
- filesize: The size of the file.
- arch: The architecture of the file (if applicable).
- checksum: The checksum of the file.

View file

@ -6977,6 +6977,9 @@ class CG_Importer(object):
def assert_policy(self):
policy_data = {
'package': self.buildinfo['name'],
'version': self.buildinfo['version'],
'release': self.buildinfo['release'],
'btypes': list(self.typeinfo),
'source': self.buildinfo.get('source'),
'metadata_only': self.metadata_only,
'cg_list': [self.cg],
@ -7397,6 +7400,8 @@ class CG_Importer(object):
if fileinfo['type'] not in ['rpm', 'log']:
self.prep_archive(fileinfo)
if fileinfo['type'] == 'rpm':
if fileinfo.get('subdir'):
raise koji.GenericError("subdir field not allowed for rpm outputs")
koji.check_NVRA(fileinfo['filename'], strict=True)
outputs.append(fileinfo)
self.prepped_outputs = outputs
@ -7430,6 +7435,8 @@ class CG_Importer(object):
"%(filename)s" % fileinfo)
btype = key
type_info = extra[key]
if fileinfo.get('subdir'):
raise koji.GenericError("subdir field not allowed for legacy btypes")
for key in extra.get('typeinfo', {}):
if btype == key:
raise koji.GenericError("Duplicate typeinfo for: %r" % btype)
@ -7473,9 +7480,9 @@ class CG_Importer(object):
if fileinfo.get('metadata_only', False):
# logs are not currently tracked, so this is a no op
return
# TODO: determine subdir
subdir = fileinfo.get('subdir')
fn = fileinfo['hub.path']
import_build_log(fn, buildinfo, subdir=None)
import_build_log(fn, buildinfo, subdir=subdir)
def import_archive(self, buildinfo, brinfo, fileinfo):
fn = fileinfo['hub.path']
@ -7585,9 +7592,9 @@ def import_build_log(fn, buildinfo, subdir=None):
"""Move a logfile related to a build to the right place"""
logdir = koji.pathinfo.build_logs(buildinfo)
if subdir:
logdir = "%s/%s" % (logdir, subdir)
logdir = joinpath(logdir, subdir)
koji.ensuredir(logdir)
final_path = "%s/%s" % (logdir, os.path.basename(fn))
final_path = joinpath(logdir, os.path.basename(fn))
if os.path.exists(final_path):
raise koji.GenericError("Error importing build log. %s already exists." % final_path)
if os.path.islink(fn) or not os.path.isfile(fn):
@ -8088,6 +8095,9 @@ def import_archive_internal(filepath, buildinfo, type, typeInfo, buildroot_id=No
# new style type, no supplementary table
if not metadata_only:
destdir = koji.pathinfo.typedir(buildinfo, btype['name'])
subdir = fileinfo.get('subdir')
if subdir:
destdir = joinpath(destdir, subdir)
_import_archive_file(filepath, destdir)
archiveinfo = get_archive(archive_id, strict=True)