Replace simple sh -c runcmd() users with direct argv calls where the commands do not need shell syntax.
Also replace the cat-to-file redirection used when appending patch files with shutil.copyfile(). Reviewed-by: Daniel Turull <[email protected]> Signed-off-by: Anders Heimer <[email protected]> --- meta/lib/oe/patch.py | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py index b152a2d784..290eb990f1 100644 --- a/meta/lib/oe/patch.py +++ b/meta/lib/oe/patch.py @@ -195,10 +195,12 @@ class PatchTree(PatchSet): bb.utils.mkdirhier(self.patchdir) def _appendPatchFile(self, patch, strippath): + import shutil + with open(self.seriespath, 'a') as f: f.write(os.path.basename(patch) + "," + strippath + "\n") - shellcmd = ["cat", patch, ">" , self.patchdir + "/" + os.path.basename(patch)] - runcmd(["sh", "-c", " ".join(shellcmd)], self.dir) + dest = os.path.join(self.patchdir, os.path.basename(patch)) + shutil.copyfile(patch, dest) def _removePatch(self, p): patch = {} @@ -433,8 +435,8 @@ class GitApplyTree(PatchTree): outlines, author, date, subject = GitApplyTree.interpretPatchHeader(lines) if not author or not subject or not date: try: - shellcmd = ["git", "log", "--format=email", "--follow", "--diff-filter=A", "--", patchfile] - out = runcmd(["sh", "-c", " ".join(shellcmd)], os.path.dirname(patchfile)) + cmd = ["git", "log", "--format=email", "--follow", "--diff-filter=A", "--", patchfile] + out = runcmd(cmd, os.path.dirname(patchfile)) except CmdError: out = None if out: @@ -525,11 +527,11 @@ class GitApplyTree(PatchTree): patches = [] try: for name, rev in startcommits.items(): - shellcmd = ["git", "format-patch", "--no-signature", "--no-numbered", rev, "-o", tempdir] + cmd = ["git", "format-patch", "--no-signature", "--no-numbered", rev, "-o", tempdir] if paths: - shellcmd.append('--') - shellcmd.extend(paths) - out = runcmd(["sh", "-c", " ".join(shellcmd)], os.path.join(tree, name)) + cmd.append('--') + cmd.extend(paths) + out = runcmd(cmd, os.path.join(tree, name)) if out: for srcfile in out.split(): # This loop, which is used to remove any line that @@ -585,11 +587,11 @@ class GitApplyTree(PatchTree): def _commitpatch(self, patch, patchfilevar): output = "" # Add all files - shellcmd = ["git", "add", "-f", "-A", "."] - output += runcmd(["sh", "-c", " ".join(shellcmd)], self.dir) + cmd = ["git", "add", "-f", "-A", "."] + output += runcmd(cmd, self.dir) # Exclude the patches directory - shellcmd = ["git", "reset", "HEAD", self.patchdir] - output += runcmd(["sh", "-c", " ".join(shellcmd)], self.dir) + cmd = ["git", "reset", "HEAD", self.patchdir] + output += runcmd(cmd, self.dir) # Commit the result (tmpfile, shellcmd) = self.prepareCommit(patch['file'], self.commituser, self.commitemail) try: @@ -642,21 +644,21 @@ class GitApplyTree(PatchTree): except CmdError: # Need to abort the git am, or we'll still be within it at the end try: - shellcmd = ["git", "--work-tree=%s" % reporoot, "am", "--abort"] - runcmd(["sh", "-c", " ".join(shellcmd)], self.dir) + cmd = ["git", "--work-tree=%s" % reporoot, "am", "--abort"] + runcmd(cmd, self.dir) except CmdError: pass # git am won't always clean up after itself, sadly, so... - shellcmd = ["git", "--work-tree=%s" % reporoot, "reset", "--hard", "HEAD"] - runcmd(["sh", "-c", " ".join(shellcmd)], self.dir) + cmd = ["git", "--work-tree=%s" % reporoot, "reset", "--hard", "HEAD"] + runcmd(cmd, self.dir) # Also need to take care of any stray untracked files - shellcmd = ["git", "--work-tree=%s" % reporoot, "clean", "-f"] - runcmd(["sh", "-c", " ".join(shellcmd)], self.dir) + cmd = ["git", "--work-tree=%s" % reporoot, "clean", "-f"] + runcmd(cmd, self.dir) # Fall back to git apply - shellcmd = ["git", "--git-dir=%s" % reporoot, "apply", "-p%s" % patch['strippath']] + cmd = ["git", "--git-dir=%s" % reporoot, "apply", "-p%s" % patch['strippath']] try: - output = _applypatchhelper(shellcmd, patch, force, reverse, run) + output = _applypatchhelper(cmd, patch, force, reverse, run) except CmdError: # Fall back to patch output = PatchTree._applypatch(self, patch, force, reverse, run)
-=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#239396): https://lists.openembedded.org/g/openembedded-core/message/239396 Mute This Topic: https://lists.openembedded.org/mt/119940614/21656 Group Owner: [email protected] Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]] -=-=-=-=-=-=-=-=-=-=-=-
