1 |
commit: d5ab84724a9a9a39546bc962cc31e694a8634436 |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Nov 29 04:52:41 2011 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Nov 29 04:52:41 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=d5ab8472 |
7 |
|
8 |
movefile: tweak unicode handling |
9 |
|
10 |
--- |
11 |
pym/portage/util/movefile.py | 20 ++++++++++++-------- |
12 |
1 files changed, 12 insertions(+), 8 deletions(-) |
13 |
|
14 |
diff --git a/pym/portage/util/movefile.py b/pym/portage/util/movefile.py |
15 |
index d15291a..fe41501 100644 |
16 |
--- a/pym/portage/util/movefile.py |
17 |
+++ b/pym/portage/util/movefile.py |
18 |
@@ -10,15 +10,16 @@ import stat |
19 |
|
20 |
import portage |
21 |
from portage import bsd_chflags, _encodings, _os_overrides, _selinux, \ |
22 |
- _unicode_decode, _unicode_func_wrapper, _unicode_module_wrapper |
23 |
+ _unicode_decode, _unicode_encode, _unicode_func_wrapper,\ |
24 |
+ _unicode_module_wrapper |
25 |
from portage.const import MOVE_BINARY |
26 |
from portage.localization import _ |
27 |
from portage.process import spawn |
28 |
from portage.util import writemsg |
29 |
|
30 |
-def _apply_stat(os, src_stat, dest): |
31 |
- os.chown(dest, src_stat.st_uid, src_stat.st_gid) |
32 |
- os.chmod(dest, stat.S_IMODE(src_stat.st_mode)) |
33 |
+def _apply_stat(src_stat, dest): |
34 |
+ _os.chown(dest, src_stat.st_uid, src_stat.st_gid) |
35 |
+ _os.chmod(dest, stat.S_IMODE(src_stat.st_mode)) |
36 |
|
37 |
if hasattr(_os, "getxattr"): |
38 |
# Python >=3.3 |
39 |
@@ -40,6 +41,7 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, |
40 |
if mysettings is None: |
41 |
mysettings = portage.settings |
42 |
|
43 |
+ src_bytes = _unicode_encode(src, encoding=encoding, errors='strict') |
44 |
selinux_enabled = mysettings.selinux_enabled() |
45 |
if selinux_enabled: |
46 |
selinux = _unicode_module_wrapper(_selinux, encoding=encoding) |
47 |
@@ -173,16 +175,18 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, |
48 |
if renamefailed: |
49 |
if stat.S_ISREG(sstat[stat.ST_MODE]): |
50 |
dest_tmp = dest + "#new" |
51 |
+ dest_tmp_bytes = _unicode_encode(dest_tmp, encoding=encoding, |
52 |
+ errors='strict') |
53 |
try: # For safety copy then move it over. |
54 |
if selinux_enabled: |
55 |
selinux.copyfile(src, dest_tmp) |
56 |
- _copyxattr(src, dest_tmp) |
57 |
- _apply_stat(os, sstat, dest_tmp) |
58 |
+ _copyxattr(src_bytes, dest_tmp_bytes) |
59 |
+ _apply_stat(sstat, dest_tmp_bytes) |
60 |
selinux.rename(dest_tmp, dest) |
61 |
else: |
62 |
shutil.copyfile(src, dest_tmp) |
63 |
- _copyxattr(src, dest_tmp) |
64 |
- _apply_stat(os, sstat, dest_tmp) |
65 |
+ _copyxattr(src_bytes, dest_tmp_bytes) |
66 |
+ _apply_stat(sstat, dest_tmp_bytes) |
67 |
os.rename(dest_tmp, dest) |
68 |
os.unlink(src) |
69 |
except SystemExit as e: |