]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/commitdiff
classes/package_rpm: correctly escape percent characters
authorAlexander Kanavin <alex.kanavin@gmail.com>
Mon, 29 Jan 2024 18:06:29 +0000 (19:06 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 2 Feb 2024 11:06:14 +0000 (11:06 +0000)
This many characters doesn't work with rpm 4.19 packaging
(as shown by nodejs recipes), and per documentation a single escape
is enough:

https://github.com/rpm-software-management/rpm/blob/rpm-4.19.x/docs/manual/spec.md#shell-globbing

It also should be done in a function, and just before writing out the
corrected filename to .spec, not earlier where the path may still
be needed for file operations (such as gettings file attributes).

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes-global/package_rpm.bbclass

index e0f4de42a153d2bb056c7e6f6e63154c2061b15a..819ee502783ba7728b6b837e2f9745dca547dfc4 100644 (file)
@@ -216,10 +216,12 @@ python write_specfile () {
                     raise e
                 return "%attr({:o},{},{}) ".format(mode, owner, group)
 
+            def escape_chars(p):
+                return p.replace("%", "%%")
+
             path = rootpath.replace(walkpath, "")
             if path.endswith("DEBIAN") or path.endswith("CONTROL"):
                 continue
-            path = path.replace("%", "%%%%%%%%")
 
             # Treat all symlinks to directories as normal files.
             # os.walk() lists them as directories.
@@ -238,29 +240,27 @@ python write_specfile () {
                 for dir in dirs:
                     if dir == "CONTROL" or dir == "DEBIAN":
                         continue
-                    dir = dir.replace("%", "%%%%%%%%")
                     p = path + '/' + dir
                     # All packages own the directories their files are in...
-                    target.append(get_attr(dir) + '%dir "' + p + '"')
+                    target.append(get_attr(dir) + '%dir "' + escape_chars(p) + '"')
             else:
                 # packages own only empty directories or explict directory.
                 # This will prevent the overlapping of security permission.
                 attr = get_attr(path)
                 if path and not files and not dirs:
-                    target.append(attr + '%dir "' + path + '"')
+                    target.append(attr + '%dir "' + escape_chars(path) + '"')
                 elif path and path in dirfiles:
-                    target.append(attr + '%dir "' + path + '"')
+                    target.append(attr + '%dir "' + escape_chars(path) + '"')
 
             for file in files:
                 if file == "CONTROL" or file == "DEBIAN":
                     continue
-                file = file.replace("%", "%%%%%%%%")
                 attr = get_attr(file)
                 p = path + '/' + file
                 if conffiles.count(p):
-                    target.append(attr + '%config "' + p + '"')
+                    target.append(attr + '%config "' + escape_chars(p) + '"')
                 else:
-                    target.append(attr + '"' + p + '"')
+                    target.append(attr + '"' + escape_chars(p) + '"')
 
     # Prevent the prerm/postrm scripts from being run during an upgrade
     def wrap_uninstall(scriptvar):