1 |
commit: ee59f1c63ecc54ad286c82c0adb2ae74011de69e |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Nov 29 04:25:54 2011 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Nov 29 04:25:54 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=ee59f1c6 |
7 |
|
8 |
movefile: chown/mod before rename |
9 |
|
10 |
--- |
11 |
pym/portage/util/movefile.py | 22 +++++++--------------- |
12 |
1 files changed, 7 insertions(+), 15 deletions(-) |
13 |
|
14 |
diff --git a/pym/portage/util/movefile.py b/pym/portage/util/movefile.py |
15 |
index c205fe9..d15291a 100644 |
16 |
--- a/pym/portage/util/movefile.py |
17 |
+++ b/pym/portage/util/movefile.py |
18 |
@@ -16,6 +16,10 @@ from portage.localization import _ |
19 |
from portage.process import spawn |
20 |
from portage.util import writemsg |
21 |
|
22 |
+def _apply_stat(os, src_stat, dest): |
23 |
+ os.chown(dest, src_stat.st_uid, src_stat.st_gid) |
24 |
+ os.chmod(dest, stat.S_IMODE(src_stat.st_mode)) |
25 |
+ |
26 |
if hasattr(_os, "getxattr"): |
27 |
# Python >=3.3 |
28 |
def _copyxattr(src, dest): |
29 |
@@ -167,19 +171,20 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, |
30 |
return None |
31 |
# Invalid cross-device-link 'bind' mounted or actually Cross-Device |
32 |
if renamefailed: |
33 |
- didcopy=0 |
34 |
if stat.S_ISREG(sstat[stat.ST_MODE]): |
35 |
dest_tmp = dest + "#new" |
36 |
try: # For safety copy then move it over. |
37 |
if selinux_enabled: |
38 |
selinux.copyfile(src, dest_tmp) |
39 |
_copyxattr(src, dest_tmp) |
40 |
+ _apply_stat(os, sstat, dest_tmp) |
41 |
selinux.rename(dest_tmp, dest) |
42 |
else: |
43 |
shutil.copyfile(src, dest_tmp) |
44 |
_copyxattr(src, dest_tmp) |
45 |
+ _apply_stat(os, sstat, dest_tmp) |
46 |
os.rename(dest_tmp, dest) |
47 |
- didcopy=1 |
48 |
+ os.unlink(src) |
49 |
except SystemExit as e: |
50 |
raise |
51 |
except Exception as e: |
52 |
@@ -196,19 +201,6 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, |
53 |
"dest": _unicode_decode(dest, encoding=encoding)}, noiselevel=-1) |
54 |
writemsg("!!! %s\n" % a, noiselevel=-1) |
55 |
return None # failure |
56 |
- try: |
57 |
- if didcopy: |
58 |
- # didcopy is True only if S_ISREG returned True |
59 |
- os.chown(dest,sstat[stat.ST_UID],sstat[stat.ST_GID]) |
60 |
- os.chmod(dest, stat.S_IMODE(sstat[stat.ST_MODE])) # Sticky is reset on chown |
61 |
- os.unlink(src) |
62 |
- except SystemExit as e: |
63 |
- raise |
64 |
- except Exception as e: |
65 |
- print(_("!!! Failed to chown/chmod/unlink in movefile()")) |
66 |
- print("!!!",dest) |
67 |
- print("!!!",e) |
68 |
- return None |
69 |
|
70 |
# Always use stat_obj[stat.ST_MTIME] for the integral timestamp which |
71 |
# is returned, since the stat_obj.st_mtime float attribute rounds *up* |