1 |
commit: a8f0e05d35b0ba2747827ce03dff42682192def8 |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Sep 9 05:08:20 2020 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Sep 11 19:00:57 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=a8f0e05d |
7 |
|
8 |
selinux: encode os path arguments as UTF-8 (bug 741194) |
9 |
|
10 |
Encode path arguments as UTF-8, like portage.os wrapper. |
11 |
|
12 |
Fixes: 6137290b2bb8 ("selinux: python3 unicode paths, bug #430488") |
13 |
Tested-by: Bob Gleitsmann <rjgleits <AT> bellsouth.net> |
14 |
Bug: https://bugs.gentoo.org/741194 |
15 |
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> |
16 |
|
17 |
lib/portage/_selinux.py | 16 ++++++++-------- |
18 |
1 file changed, 8 insertions(+), 8 deletions(-) |
19 |
|
20 |
diff --git a/lib/portage/_selinux.py b/lib/portage/_selinux.py |
21 |
index e3e18c0b8..2423ff8d6 100644 |
22 |
--- a/lib/portage/_selinux.py |
23 |
+++ b/lib/portage/_selinux.py |
24 |
@@ -14,7 +14,7 @@ except ImportError: |
25 |
|
26 |
import portage |
27 |
from portage import _encodings |
28 |
-from portage import _native_string |
29 |
+from portage import _native_string, _unicode_encode |
30 |
from portage.localization import _ |
31 |
|
32 |
def copyfile(src, dest): |
33 |
@@ -41,7 +41,6 @@ def is_selinux_enabled(): |
34 |
return selinux.is_selinux_enabled() |
35 |
|
36 |
def mkdir(target, refdir): |
37 |
- target = _native_string(target, encoding=_encodings['fs'], errors='strict') |
38 |
refdir = _native_string(refdir, encoding=_encodings['fs'], errors='strict') |
39 |
(rc, ctx) = selinux.getfilecon(refdir) |
40 |
if rc < 0: |
41 |
@@ -51,20 +50,21 @@ def mkdir(target, refdir): |
42 |
|
43 |
setfscreate(ctx) |
44 |
try: |
45 |
- os.mkdir(target) |
46 |
+ os.mkdir(_unicode_encode(target, encoding=_encodings['fs'], errors='strict')) |
47 |
finally: |
48 |
setfscreate() |
49 |
|
50 |
def rename(src, dest): |
51 |
src = _native_string(src, encoding=_encodings['fs'], errors='strict') |
52 |
- dest = _native_string(dest, encoding=_encodings['fs'], errors='strict') |
53 |
(rc, ctx) = selinux.lgetfilecon(src) |
54 |
if rc < 0: |
55 |
raise OSError(_("rename: Failed getting context of \"%s\".") % src) |
56 |
|
57 |
setfscreate(ctx) |
58 |
try: |
59 |
- os.rename(src, dest) |
60 |
+ os.rename( |
61 |
+ _unicode_encode(src, encoding=_encodings['fs'], errors='strict'), |
62 |
+ _unicode_encode(dest, encoding=_encodings['fs'], errors='strict')) |
63 |
finally: |
64 |
setfscreate() |
65 |
|
66 |
@@ -132,8 +132,6 @@ class spawn_wrapper: |
67 |
return self._spawn_func(*args, **kwargs) |
68 |
|
69 |
def symlink(target, link, reflnk): |
70 |
- target = _native_string(target, encoding=_encodings['fs'], errors='strict') |
71 |
- link = _native_string(link, encoding=_encodings['fs'], errors='strict') |
72 |
reflnk = _native_string(reflnk, encoding=_encodings['fs'], errors='strict') |
73 |
(rc, ctx) = selinux.lgetfilecon(reflnk) |
74 |
if rc < 0: |
75 |
@@ -143,6 +141,8 @@ def symlink(target, link, reflnk): |
76 |
|
77 |
setfscreate(ctx) |
78 |
try: |
79 |
- os.symlink(target, link) |
80 |
+ os.symlink( |
81 |
+ _unicode_encode(target, encoding=_encodings['fs'], errors='strict'), |
82 |
+ _unicode_encode(link, encoding=_encodings['fs'], errors='strict')) |
83 |
finally: |
84 |
setfscreate() |