summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2012-03-23 11:05:36 -0700
committerZac Medico <zmedico@gentoo.org>2012-03-23 11:20:14 -0700
commit6d2be766e6056e266522c9e39d663d7c0ac42e0d (patch)
treeab96c3e80e5df7c523c991f029d012586c2d5bab
parent7c58705c30fed6b11f978c4880225ced8a45c70d (diff)
downloadportage-6d2be766e6056e266522c9e39d663d7c0ac42e0d.tar.gz
portage-6d2be766e6056e266522c9e39d663d7c0ac42e0d.tar.bz2
portage-6d2be766e6056e266522c9e39d663d7c0ac42e0d.zip
movefile: refactor selinux conditional code
-rw-r--r--pym/portage/util/movefile.py28
1 files changed, 13 insertions, 15 deletions
diff --git a/pym/portage/util/movefile.py b/pym/portage/util/movefile.py
index 476f8e72a..252f4a292 100644
--- a/pym/portage/util/movefile.py
+++ b/pym/portage/util/movefile.py
@@ -1,4 +1,4 @@
-# Copyright 2010-2011 Gentoo Foundation
+# Copyright 2010-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
__all__ = ['movefile']
@@ -85,15 +85,20 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None,
mysettings = portage.settings
src_bytes = _unicode_encode(src, encoding=encoding, errors='strict')
+ dest_bytes = _unicode_encode(dest, encoding=encoding, errors='strict')
xattr_enabled = "xattr" in mysettings.features
selinux_enabled = mysettings.selinux_enabled()
if selinux_enabled:
selinux = _unicode_module_wrapper(_selinux, encoding=encoding)
+ _copyfile = selinux.copyfile
+ _rename = selinux.rename
+ else:
+ _copyfile = _shutil.copyfile
+ _rename = _os.rename
lchown = _unicode_func_wrapper(portage.data.lchown, encoding=encoding)
os = _unicode_module_wrapper(_os,
encoding=encoding, overrides=_os_overrides)
- shutil = _unicode_module_wrapper(_shutil, encoding=encoding)
try:
if not sstat:
@@ -222,19 +227,12 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None,
dest_tmp_bytes = _unicode_encode(dest_tmp, encoding=encoding,
errors='strict')
try: # For safety copy then move it over.
- if selinux_enabled:
- selinux.copyfile(src, dest_tmp)
- if xattr_enabled:
- _copyxattr(src_bytes, dest_tmp_bytes)
- _apply_stat(sstat, dest_tmp_bytes)
- selinux.rename(dest_tmp, dest)
- else:
- shutil.copyfile(src, dest_tmp)
- if xattr_enabled:
- _copyxattr(src_bytes, dest_tmp_bytes)
- _apply_stat(sstat, dest_tmp_bytes)
- os.rename(dest_tmp, dest)
- os.unlink(src)
+ _copyfile(src_bytes, dest_tmp_bytes)
+ if xattr_enabled:
+ _copyxattr(src_bytes, dest_tmp_bytes)
+ _apply_stat(sstat, dest_tmp_bytes)
+ _rename(dest_tmp_bytes, dest_bytes)
+ _os.unlink(src_bytes)
except SystemExit as e:
raise
except Exception as e: