#1829 Add a sanity check on remotely opened RPMs
Merged 2 years ago by tkopecek. Opened 2 years ago by tkopecek.
tkopecek/koji issue290  into  master

file modified
+1
@@ -1101,6 +1101,7 @@ 

          opts = dict([(k, getattr(self.options, k)) for k in ('topurl','topdir')])

          opts['tempdir'] = self.workdir

          with koji.openRemoteFile(relpath, **opts) as fo:

+             koji.check_rpm_file(fo)

              h = koji.get_rpm_header(fo)

          if not koji.get_header_field(h, 'sourcepackage'):

              raise koji.BuildError("%s is not a source package" % srpm)

file modified
+32
@@ -1680,6 +1680,38 @@ 

      return fo

  

  

+ def check_rpm_file(rpmfile):

+     """Do a initial sanity check on an RPM

+ 

+     rpmfile can either be a file name or a file object

+ 

+     This check is used to detect issues with RPMs before they break builds

+     See: https://pagure.io/koji/issue/290

+     """

+     if isinstance(rpmfile, six.string_types):

+         with open(rpmfile, 'rb') as fo:

+             return _check_rpm_file(fo)

+     else:

+         return _check_rpm_file(rpmfile)

+ 

+ 

+ def _check_rpm_file(fo):

+     """Check that the open file appears to be an rpm"""

+     # TODO: trap exception and raise something with more infomation

+     ts = rpm.TransactionSet()

+     try:

+         hdr = ts.hdrFromFdno(fo.fileno())

+     except rpm.error as ex:

+         raise GenericError("rpm's header can't be extracted: %s (rpm error: %s)" % \

+                            (fo.name, ', '.join(ex.args)))

+     try:

+         rpm.TransactionSet().hdrCheck(hdr.unload())

+     except rpm.error as ex:

+         raise GenericError("rpm's header can't be checked: %s (rpm error: %s)" % \

+                            (fo.name, ', '.join(ex.args)))

+     fo.seek(0)

+ 

+ 

  def config_directory_contents(dir_name, strict=False):

      configs = []

      try:

3 new commits added

  • added koji exceptions
  • refactor
  • Add a sanity check on remotely opened RPMs
2 years ago

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

2 years ago

Commit 7afba10 fixes this pull-request

Pull-Request has been merged by tkopecek

2 years ago

Metadata Update from @jcupova:
- Pull-request tagged with: testing-done

2 years ago