public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Zac Medico <zmedico@gentoo.org>
To: gentoo-portage-dev@lists.gentoo.org
Cc: Zac Medico <zmedico@gentoo.org>
Subject: [gentoo-portage-dev] [PATCH] selinux: encode os path arguments as UTF-8 (bug 741194)
Date: Tue,  8 Sep 2020 22:29:29 -0700	[thread overview]
Message-ID: <20200909052929.48160-1-zmedico@gentoo.org> (raw)

Encode path arguments as UTF-8, like portage.os wrapper.

Fixes: 6137290b2bb8 ("selinux: python3 unicode paths, bug #430488")
Bug: https://bugs.gentoo.org/741194
Signed-off-by: Zac Medico <zmedico@gentoo.org>
---
 lib/portage/_selinux.py | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/portage/_selinux.py b/lib/portage/_selinux.py
index e3e18c0b8..2423ff8d6 100644
--- a/lib/portage/_selinux.py
+++ b/lib/portage/_selinux.py
@@ -14,7 +14,7 @@ except ImportError:
 
 import portage
 from portage import _encodings
-from portage import _native_string
+from portage import _native_string, _unicode_encode
 from portage.localization import _
 
 def copyfile(src, dest):
@@ -41,7 +41,6 @@ def is_selinux_enabled():
 	return selinux.is_selinux_enabled()
 
 def mkdir(target, refdir):
-	target = _native_string(target, encoding=_encodings['fs'], errors='strict')
 	refdir = _native_string(refdir, encoding=_encodings['fs'], errors='strict')
 	(rc, ctx) = selinux.getfilecon(refdir)
 	if rc < 0:
@@ -51,20 +50,21 @@ def mkdir(target, refdir):
 
 	setfscreate(ctx)
 	try:
-		os.mkdir(target)
+		os.mkdir(_unicode_encode(target, encoding=_encodings['fs'], errors='strict'))
 	finally:
 		setfscreate()
 
 def rename(src, dest):
 	src = _native_string(src, encoding=_encodings['fs'], errors='strict')
-	dest = _native_string(dest, encoding=_encodings['fs'], errors='strict')
 	(rc, ctx) = selinux.lgetfilecon(src)
 	if rc < 0:
 		raise OSError(_("rename: Failed getting context of \"%s\".") % src)
 
 	setfscreate(ctx)
 	try:
-		os.rename(src, dest)
+		os.rename(
+			_unicode_encode(src, encoding=_encodings['fs'], errors='strict'),
+			_unicode_encode(dest, encoding=_encodings['fs'], errors='strict'))
 	finally:
 		setfscreate()
 
@@ -132,8 +132,6 @@ class spawn_wrapper:
 		return self._spawn_func(*args, **kwargs)
 
 def symlink(target, link, reflnk):
-	target = _native_string(target, encoding=_encodings['fs'], errors='strict')
-	link = _native_string(link, encoding=_encodings['fs'], errors='strict')
 	reflnk = _native_string(reflnk, encoding=_encodings['fs'], errors='strict')
 	(rc, ctx) = selinux.lgetfilecon(reflnk)
 	if rc < 0:
@@ -143,6 +141,8 @@ def symlink(target, link, reflnk):
 
 	setfscreate(ctx)
 	try:
-		os.symlink(target, link)
+		os.symlink(
+			_unicode_encode(target, encoding=_encodings['fs'], errors='strict'),
+			_unicode_encode(link, encoding=_encodings['fs'], errors='strict'))
 	finally:
 		setfscreate()
-- 
2.25.3



                 reply	other threads:[~2020-09-09  5:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200909052929.48160-1-zmedico@gentoo.org \
    --to=zmedico@gentoo.org \
    --cc=gentoo-portage-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox