| |
@@ -320,3 +320,23 @@
|
| |
# output contains encoding ("binary", "us-ascii", ...)
|
| |
encoding = output.strip() # strip newline at the end
|
| |
return encoding == "binary"
|
| |
+
|
| |
+ def spec_file_processed_by_rpmautospec(file_name, dir_path=None):
|
| |
+ file_path = os.path.join(dir_path or "", file_name)
|
| |
+
|
| |
+ try:
|
| |
+ contents = open(file_path).readlines()
|
| |
+ except Exception:
|
| |
+ # if we can't read it, let's assume the answer is "no".
|
| |
+ return False
|
| |
+
|
| |
+ # Check for the %autorelease header prepended to the file
|
| |
+ if any('START: Set by rpmautospec' in line for line in contents[:10]):
|
| |
+ return True
|
| |
+
|
| |
+ # It seems that currently there's no mechanism to detect
|
| |
+ # %autochangelog processing. But most packages would use both
|
| |
+ # %autochangelog and %autorelease together, so we should catch
|
| |
+ # most cases by checking for %autorelease only.
|
| |
+ # https://pagure.io/fedora-infra/rpmautospec/issue/269
|
| |
+ return False
|
| |
People occasionally try to do 'fedpkg/rpm import' on an srpm which was
built from a .spec file with %autorelease and %autochangelog fields.
rpmautospec works by replacing those macros with generated content.
Importing and srpm after such processing is generally the wrong thing
to do, because for %autorelease and %autochangelog to work, the spec
file with (unexpanded) macros must be stored in dist-git. But even if
somebody wanted to stop using rpmautospec, and wanted to import the
processed spec file, the headers that were inserted by rpmautospec
should be removed. Thus, just refuse such imports.
Note that I also opened https://pagure.io/fedora-infra/rpmautospec/issue/269
to provide an "official" way to detect that the file was processed.
But even the current imperfect check is better than nothing because
it seems to be a fairly common mistake because 'fedpkg import' is
a very common workflow, and %autorelease/%autochangelog are becoming
the norm too.
Test:
$ PYTHONPATH=$HOME/python/rpkg fedpkg import --offline package-notes-0.5-3.fc38.src.rpm
Could not execute import_srpm: srpm was processed by rpmautospec
Signed-off-by: Zbigniew Jędrzejewski-Szmek zbyszek@in.waw.pl