summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pym/portage/__init__.py17
-rw-r--r--pym/portage/checksum.py4
-rw-r--r--pym/portage/dbapi/vartree.py74
-rw-r--r--pym/portage/util.py12
4 files changed, 87 insertions, 20 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index f20284e30..0dd901dbe 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -204,6 +204,7 @@ import os as _os
_os_overrides = {
id(_os.fdopen) : _os.fdopen,
id(_os.read) : _os.read,
+ id(_os.system) : _os.system,
}
os = _unicode_module_wrapper(_os, overrides=_os_overrides)
@@ -216,6 +217,7 @@ shutil = _unicode_module_wrapper(_shutil)
# Imports below this point rely on the above unicode wrapper definitions.
_selinux = None
selinux = None
+_selinux_merge = _unicode_module_wrapper(_selinux, encoding=_merge_encoding)
try:
import portage._selinux
selinux = _unicode_module_wrapper(_selinux)
@@ -401,9 +403,9 @@ if platform.system() in ('FreeBSD',):
return
# Try to generate an ENOENT error if appropriate.
if 'h' in opts:
- os.lstat(path)
+ _os_merge.lstat(path)
else:
- os.stat(path)
+ _os_merge.stat(path)
# Make sure the binary exists.
if not portage.process.find_binary('chflags'):
raise portage.exception.CommandNotFound('chflags')
@@ -5533,6 +5535,9 @@ def _post_src_install_uid_fix(mysettings):
S_ISUID and S_ISGID bits, so those bits are restored if
necessary.
"""
+
+ os = _os_merge
+
inst_uid = int(mysettings["PORTAGE_INST_UID"])
inst_gid = int(mysettings["PORTAGE_INST_GID"])
@@ -5552,9 +5557,9 @@ def _post_src_install_uid_fix(mysettings):
counted_inodes = set()
for parent, dirs, files in os.walk(destdir):
- parent = _unicode_decode(parent)
+ parent = _unicode_decode(parent, encoding=_merge_encoding)
for fname in chain(dirs, files):
- fname = _unicode_decode(fname)
+ fname = _unicode_decode(fname, encoding=_merge_encoding)
fpath = os.path.join(parent, fname)
mystat = os.lstat(fpath)
if stat.S_ISREG(mystat.st_mode) and \
@@ -5570,7 +5575,9 @@ def _post_src_install_uid_fix(mysettings):
myuid = inst_uid
if mystat.st_gid == portage_gid:
mygid = inst_gid
- apply_secpass_permissions(fpath, uid=myuid, gid=mygid,
+ apply_secpass_permissions(
+ _unicode_encode(fpath, encoding=_merge_encoding),
+ uid=myuid, gid=mygid,
mode=mystat.st_mode, stat_cached=mystat,
follow_links=False)
diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py
index 501ae3e6a..5def1ac8a 100644
--- a/pym/portage/checksum.py
+++ b/pym/portage/checksum.py
@@ -6,6 +6,7 @@
import portage
from portage.const import PRIVATE_PATH,PRELINK_BINARY,HASHING_BLOCKSIZE
from portage import os
+from portage import _merge_encoding
from portage import _unicode_encode
import errno
import stat
@@ -117,6 +118,9 @@ if os.path.exists(PRELINK_BINARY):
def perform_md5(x, calc_prelink=0):
return perform_checksum(x, "MD5", calc_prelink)[0]
+def _perform_md5_merge(x, **kwargs):
+ return perform_md5(_unicode_encode(x, encoding=_merge_encoding), **kwargs)
+
def perform_all(x, calc_prelink=0):
mydict = {}
for k in hashfunc_map:
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index 18c387ee7..d0a389ee5 100644
--- a/pym/portage/dbapi/vartree.py
+++ b/pym/portage/dbapi/vartree.py
@@ -8,7 +8,7 @@ __all__ = ["PreservedLibsRegistry", "LinkageMap",
import portage
portage.proxy.lazyimport.lazyimport(globals(),
- 'portage.checksum:perform_md5',
+ 'portage.checksum:_perform_md5_merge@perform_md5',
'portage.dep:dep_getkey,isjustname,isvalidatom,match_from_list,' + \
'use_reduce,paren_reduce',
'portage.elog:elog_process',
@@ -37,8 +37,10 @@ from portage import listdir, dep_expand, digraph, flatten, key_expand, \
# This is a special version of the os module, wrapped for unicode support.
from portage import os
+from portage import _merge_encoding
+from portage import _os_merge
+from portage import _selinux_merge
from portage import _unicode_encode
-from portage import selinux
from portage.cache.mappings import slot_dict_class
@@ -140,6 +142,9 @@ class PreservedLibsRegistry(object):
def pruneNonExisting(self):
""" Remove all records for objects that no longer exist on the filesystem. """
+
+ os = _os_merge
+
for cps in self._data.keys():
cpv, counter, paths = self._data[cps]
paths = [f for f in paths \
@@ -239,6 +244,9 @@ class LinkageMap(object):
2. realpath of object if object does not exist.
"""
+
+ os = _os_merge
+
abs_path = os.path.join(root, obj.lstrip(os.sep))
try:
object_stat = os.stat(abs_path)
@@ -276,6 +284,8 @@ class LinkageMap(object):
Raises CommandNotFound if there are preserved libs
and the scanelf binary is not available.
"""
+
+ os = _os_merge
root = self._root
root_len = len(root) - 1
self._clear_cache()
@@ -395,6 +405,9 @@ class LinkageMap(object):
object that have no corresponding libraries to fulfill the dependency.
"""
+
+ os = _os_merge
+
class _LibraryCache(object):
"""
@@ -541,6 +554,7 @@ class LinkageMap(object):
2. False if obj is not a master link
"""
+ os = _os_merge
basename = os.path.basename(obj)
obj_key = self._obj_key(obj)
if obj_key not in self._obj_properties:
@@ -608,6 +622,9 @@ class LinkageMap(object):
set-of-library-paths satisfy soname.
"""
+
+ os = _os_merge
+
rValue = {}
if not self._libs:
@@ -668,6 +685,9 @@ class LinkageMap(object):
set-of-library-paths satisfy soname.
"""
+
+ os = _os_merge
+
rValue = set()
if not self._libs:
@@ -2265,6 +2285,7 @@ class dblink(object):
@rtype: None
"""
+ os = _os_merge
showMessage = self._display_merge
scheduler = self._scheduler
@@ -2540,6 +2561,8 @@ class dblink(object):
if the file is not owned by this package.
"""
+ os = _os_merge
+
filename = portage._unicode_decode(filename)
destroot = portage._unicode_decode(destroot)
@@ -2624,6 +2647,7 @@ class dblink(object):
"preserve-libs" in self.settings.features):
return None
+ os = _os_merge
linkmap = self.vartree.dbapi.linkmap
installed_instance = self._installed_instance
old_contents = installed_instance.getcontents()
@@ -2719,6 +2743,7 @@ class dblink(object):
if not preserve_paths:
return
+ os = _os_merge
showMessage = self._display_merge
root = self.myroot
@@ -2726,7 +2751,7 @@ class dblink(object):
new_contents = self.getcontents().copy()
old_contents = self._installed_instance.getcontents()
for f in sorted(preserve_paths):
- f = portage._unicode_decode(f)
+ f = portage._unicode_decode(f, encoding=_merge_encoding)
f_abs = os.path.join(root, f.lstrip(os.sep))
contents_entry = old_contents.get(f_abs)
if contents_entry is None:
@@ -2865,6 +2890,8 @@ class dblink(object):
Remove files returned from _find_unused_preserved_libs().
"""
+ os = _os_merge
+
files_to_remove = set()
for files in cpv_lib_map.itervalues():
files_to_remove.update(files)
@@ -2906,6 +2933,9 @@ class dblink(object):
self.vartree.dbapi.plib_registry.pruneNonExisting()
def _collision_protect(self, srcroot, destroot, mypkglist, mycontents):
+
+ os = _os_merge
+
collision_ignore = set([normalize_path(myignore) for myignore in \
portage.util.shlex_split(
self.settings.get("COLLISION_IGNORE", ""))])
@@ -3017,6 +3047,9 @@ class dblink(object):
Multiple paths may reference the same inode due to hardlinks.
All lstat() calls are relative to self.myroot.
"""
+
+ os = _os_merge
+
root = self.myroot
inode_map = {}
for f in path_iter:
@@ -3040,6 +3073,8 @@ class dblink(object):
if not installed_instances:
return 0
+ os = _os_merge
+
showMessage = self._display_merge
scheduler = self._scheduler
@@ -3150,6 +3185,8 @@ class dblink(object):
not existing; we will merge these symlinks at a later time.
"""
+ os = _os_merge
+
srcroot = portage._unicode_decode(srcroot)
destroot = portage._unicode_decode(destroot)
inforoot = portage._unicode_decode(inforoot)
@@ -3248,9 +3285,9 @@ class dblink(object):
def onerror(e):
raise
for parent, dirs, files in os.walk(srcroot, onerror=onerror):
- parent = portage._unicode_decode(parent)
+ parent = portage._unicode_decode(parent, encoding=_merge_encoding)
for f in files:
- f = portage._unicode_decode(f)
+ f = portage._unicode_decode(f, encoding=_merge_encoding)
file_path = os.path.join(parent, f)
relative_path = file_path[srcroot_len:]
@@ -3730,8 +3767,9 @@ class dblink(object):
writemsg = self._display_merge
scheduler = self._scheduler
- sep = portage.os.sep
- join = portage.os.path.join
+ os = _os_merge
+ sep = os.sep
+ join = os.path.join
srcroot = normalize_path(srcroot).rstrip(sep) + sep
destroot = normalize_path(destroot).rstrip(sep) + sep
@@ -3814,7 +3852,9 @@ class dblink(object):
secondhand.append(mysrc[len(srcroot):])
continue
# unlinking no longer necessary; "movefile" will overwrite symlinks atomically and correctly
- mymtime = movefile(mysrc, mydest, newmtime=thismtime, sstat=mystat, mysettings=self.settings)
+ mymtime = movefile(mysrc, mydest, newmtime=thismtime,
+ sstat=mystat, mysettings=self.settings,
+ encoding=_merge_encoding)
if mymtime != None:
showMessage(">>> %s -> %s\n" % (mydest, myto))
outfile.write("sym "+myrealdest+" -> "+myto+" "+str(mymtime)+"\n")
@@ -3852,13 +3892,15 @@ class dblink(object):
bsd_chflags.lchflags(mydest, dflags)
else:
# a non-directory and non-symlink-to-directory. Won't work for us. Move out of the way.
- if movefile(mydest, mydest+".backup", mysettings=self.settings) is None:
+ if movefile(mydest, mydest+".backup",
+ mysettings=self.settings,
+ encoding=_merge_encoding) is None:
return 1
showMessage(_("bak %s %s.backup\n") % (mydest, mydest),
level=logging.ERROR, noiselevel=-1)
#now create our directory
if self.settings.selinux_enabled():
- selinux.mkdir(mydest, mysrc)
+ _selinux_merge.mkdir(mydest, mysrc)
else:
os.mkdir(mydest)
if bsd_chflags:
@@ -3869,7 +3911,7 @@ class dblink(object):
else:
#destination doesn't exist
if self.settings.selinux_enabled():
- selinux.mkdir(mydest, mysrc)
+ _selinux_merge.mkdir(mydest, mysrc)
else:
os.mkdir(mydest)
os.chmod(mydest, mystat[0])
@@ -3956,7 +3998,8 @@ class dblink(object):
mymtime = movefile(mysrc, mydest, newmtime=thismtime,
sstat=mystat, mysettings=self.settings,
- hardlink_candidates=hardlink_candidates)
+ hardlink_candidates=hardlink_candidates,
+ encoding=_merge_encoding)
if mymtime is None:
return 1
if hardlink_candidates is not None:
@@ -3971,7 +4014,9 @@ class dblink(object):
zing = "!!!"
if mydmode is None:
# destination doesn't exist
- if movefile(mysrc, mydest, newmtime=thismtime, sstat=mystat, mysettings=self.settings) != None:
+ if movefile(mysrc, mydest, newmtime=thismtime,
+ sstat=mystat, mysettings=self.settings,
+ encoding=_merge_encoding) is not None:
zing = ">>>"
else:
return 1
@@ -4122,6 +4167,7 @@ def write_contents(contents, root, f):
f.write(line)
def tar_contents(contents, root, tar, protect=None, onProgress=None):
+ os = _os_merge
from portage.util import normalize_path
import tarfile
root = normalize_path(root).rstrip(os.path.sep) + os.path.sep
@@ -4168,7 +4214,7 @@ def tar_contents(contents, root, tar, protect=None, onProgress=None):
tarinfo.size = 0
tar.addfile(tarinfo)
else:
- f = open(_unicode_encode(path), 'rb')
+ f = open(_unicode_encode(path, encoding=_merge_encoding), 'rb')
try:
tar.addfile(tarinfo, f)
finally:
diff --git a/pym/portage/util.py b/pym/portage/util.py
index 23cf93f29..94f3b52c5 100644
--- a/pym/portage/util.py
+++ b/pym/portage/util.py
@@ -24,6 +24,8 @@ import sys
import portage
from portage import os
+from portage import _merge_encoding
+from portage import _os_merge
from portage import _unicode_encode
from portage import _unicode_decode
from portage.exception import PortageException, FileNotFound, \
@@ -1203,6 +1205,9 @@ class ConfigProtect(object):
def updateprotect(self):
"""Update internal state for isprotected() calls. Nonexistent paths
are ignored."""
+
+ os = _os_merge
+
self.protect = []
self._dirs = set()
for x in self.protect_list:
@@ -1279,6 +1284,9 @@ def new_protect_filename(mydest, newmd5=None):
# config protection filename format:
# ._cfg0000_foo
# 0123456789012
+
+ os = _os_merge
+
prot_num = -1
last_pfile = ""
@@ -1307,7 +1315,7 @@ def new_protect_filename(mydest, newmd5=None):
if last_pfile and newmd5:
import portage.checksum
try:
- last_pfile_md5 = portage.checksum.perform_md5(old_pfile)
+ last_pfile_md5 = portage.checksum._perform_md5_merge(old_pfile)
except FileNotFound:
# The file suddenly disappeared or it's a broken symlink.
pass
@@ -1326,6 +1334,8 @@ def find_updated_config_files(target_root, config_protect):
If no configuration files needs to be updated, None is returned
"""
+ os = _os_merge
+
if config_protect:
# directories with some protect files in them
for x in config_protect: