Compare commits

...

3 Commits

Author SHA1 Message Date
Matthew Johnson 8bc25eebe3 Release v1.1.1
This release adds quoting ("") around filenames with whitespace in them.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-10-19 14:23:45 -07:00
Brett T. Warden 4004cffc23 specfiles: Quote filenames
In %files sections, double-quote any filenames containing a space or
tab. Uses a regex to detect and not quote rpm directive prefixes.

Fixes #32.

Signed-off-by: Brett T. Warden <brett.t.warden@intel.com>
2017-10-19 14:05:39 -07:00
Brett T. Warden a3589e1a70 tests: add leading slash to test filenames
Tests for the %files section use bare file names. Since rpmbuild
requires leading slashes anyway, adding slashes to some of the tests.

Adding new tests for filenames with white space and/or rpm directives.

Signed-off-by: Brett T. Warden <brett.t.warden@intel.com>
2017-10-19 14:05:39 -07:00
3 changed files with 40 additions and 6 deletions
+30 -2
View File
@@ -315,7 +315,7 @@ class Specfile(object):
self._write("%defattr(-,root,root,-)\n")
if "main" in self.packages:
for filename in sorted(self.packages["main"]):
self._write("{}\n".format(filename))
self._write("{}\n".format(self.quote_filename(filename)))
for pkg in sorted(self.packages):
if pkg in ["ignore", "main", "locales"]:
@@ -324,7 +324,7 @@ class Specfile(object):
self._write("\n%files {}\n".format(pkg))
self._write("%defattr(-,root,root,-)\n")
for filename in sorted(self.packages[pkg]):
self._write("{}\n".format(filename))
self._write("{}\n".format(self.quote_filename(filename)))
def write_lang_files(self):
"""
@@ -1162,3 +1162,31 @@ class Specfile(object):
def _write_strip(self, string):
self.specfile.write_strip(string)
def quote_filename(self, filename):
"""
Quotes the filename, if necessary. Identifies and skips any RPM directive prefix.
"""
# Characters that require quoting -- only those with special
# meaning in specfiles
special_chars = set(" \t")
# Build up the output as a string
quoted = ''
# Capture any directive prefix separately from actual filename
# (1 )(3 )
directive_re = re.compile("(%\w+(\([^\)]*\))?\s+)(.*)")
parts = directive_re.match(filename)
if parts:
# Add prefix to the output
quoted += parts.group(1)
# Set the filename to the remaining portion
filename = parts.group(3)
# Now check for special characters
if any(c in filename for c in special_chars):
# Quote the filename
quoted += '"{}"'.format(filename)
else:
# Add the filename as-is
quoted += filename
return quoted
+1 -1
View File
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import sys, os
version = "1.1.0"
version = "1.1.1"
def readme():
with open("README.rst") as f:
+9 -3
View File
@@ -343,15 +343,21 @@ class TestSpecfileWrite(unittest.TestCase):
"""
test write_files base test.
"""
self.specfile.packages["main"] = ["mainfile1", "mainfile2", "mainfile3"]
self.specfile.packages["main"] = ["mainfile1", "/mainfile2", "/mainfile3",
"/mainfile 4", "mainfile\t5", "%foo /mainfile6", "%bar /mainfile 7"]
self.specfile.packages["ignore"] = ["ignorepkg"]
self.specfile.packages["other"] = ["other2", "other1"]
self.specfile.write_files()
# Note the special sorting
expect = ["\n%files\n",
"%defattr(-,root,root,-)\n",
'%bar "/mainfile 7"\n',
"%foo /mainfile6\n",
'"/mainfile 4"\n',
"/mainfile2\n",
"/mainfile3\n",
'"mainfile\t5"\n',
"mainfile1\n",
"mainfile2\n",
"mainfile3\n",
"\n%files other\n",
"%defattr(-,root,root,-)\n",
"other1\n",