Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# EAPI (characters allowed in package names may vary).
if not isvalidatom(newcp, eapi=mycpv.eapi):
continue
mynewcpv = mycpv.replace(mycpv_cp, str(newcp), 1)
myoldpkg = catsplit(mycpv)[1]
mynewpkg = catsplit(mynewcpv)[1]
if (mynewpkg != myoldpkg) and os.path.exists(self.getname(mynewcpv)):
writemsg(_("!!! Cannot update binary: Destination exists.\n"),
noiselevel=-1)
writemsg("!!! "+mycpv+" -> "+mynewcpv+"\n", noiselevel=-1)
continue
tbz2path = self.getname(mycpv)
if os.path.exists(tbz2path) and not os.access(tbz2path,os.W_OK):
writemsg(_("!!! Cannot update readonly binary: %s\n") % mycpv,
noiselevel=-1)
continue
moves += 1
mytbz2 = portage.xpak.tbz2(tbz2path)
mydata = mytbz2.get_data()
updated_items = update_dbentries([mylist], mydata, parent=mycpv)
mydata.update(updated_items)
mydata[b'PF'] = \
_unicode_encode(mynewpkg + "\n",
encoding=_encodings['repo.content'])
mydata[b'CATEGORY'] = \
_unicode_encode(mynewcat + "\n",
encoding=_encodings['repo.content'])
if mynewpkg != myoldpkg:
head, tail = os.path.split(mypath)
if head in lib_dirs:
libdir_contents_changed = True
break
if not libdir_contents_changed:
makelinks = False
if "CHOST" in settings and "CBUILD" in settings and \
settings["CHOST"] != settings["CBUILD"]:
ldconfig = find_binary("%s-ldconfig" % settings["CHOST"])
else:
ldconfig = os.path.join(eroot, "sbin", "ldconfig")
if ldconfig is None:
pass
elif not (os.access(ldconfig, os.X_OK) and os.path.isfile(ldconfig)):
ldconfig = None
# Only run ldconfig as needed
if makelinks and ldconfig:
# ldconfig has very different behaviour between FreeBSD and Linux
if ostype == "Linux" or ostype.lower().endswith("gnu"):
# We can't update links if we haven't cleaned other versions first, as
# an older package installed ON TOP of a newer version will cause ldconfig
# to overwrite the symlinks we just made. -X means no links. After 'clean'
# we can safely create links.
writemsg_level(_(">>> Regenerating %setc/ld.so.cache...\n") % \
(target_root,))
os.system("cd / ; %s -X -r '%s'" % (ldconfig, target_root))
elif ostype in ("FreeBSD", "DragonFly"):
writemsg_level(_(">>> Regenerating %svar/run/ld-elf.so.hints...\n") % \
target_root)
somewhere else.)
"""
# mycommand is either a str or a list
if isinstance(mycommand, str):
mycommand = mycommand.split()
env = os.environ if env is None else env
# If an absolute path to an executable file isn't given
# search for it unless we've been told not to.
binary = mycommand[0]
if binary not in (BASH_BINARY, SANDBOX_BINARY, FAKEROOT_BINARY) and \
(not os.path.isabs(binary) or not os.path.isfile(binary)
or not os.access(binary, os.X_OK)):
binary = path_lookup and find_binary(binary) or None
if not binary:
raise CommandNotFound(mycommand[0])
# If we haven't been told what file descriptors to use
# default to propagating our stdin, stdout and stderr.
if fd_pipes is None:
fd_pipes = {
0:portage._get_stdin().fileno(),
1:sys.__stdout__.fileno(),
2:sys.__stderr__.fileno(),
}
# mypids will hold the pids of all processes created.
mypids = []
self.settings = settings
self.logger = logger
# Similar to emerge, sync needs a default umask so that created
# files have sane permissions.
os.umask(0o22)
self.module_controller = portage.sync.module_controller
self.module_names = self.module_controller.module_names
self.hooks = {}
for _dir in ["repo.postsync.d", "postsync.d"]:
postsync_dir = os.path.join(self.settings["PORTAGE_CONFIGROOT"],
portage.USER_CONFIG_PATH, _dir)
hooks = OrderedDict()
for filepath in util._recursive_file_list(postsync_dir):
name = filepath.split(postsync_dir)[1].lstrip(os.sep)
if os.access(filepath, os.X_OK):
hooks[filepath] = name
else:
writemsg_level(" %s %s hook: '%s' is not executable\n"
% (warn("*"), _dir, _unicode_decode(name),),
level=logging.WARN, noiselevel=2)
self.hooks[_dir] = hooks
def validate_cmd_var(v):
"""
Validate an evironment variable value to see if it
contains an executable command as the first token.
returns (valid, token_list) where 'valid' is boolean and 'token_list'
is the (possibly empty) list of tokens split by shlex.
"""
invalid = False
v_split = shlex_split(v)
if not v_split:
invalid = True
elif os.path.isabs(v_split[0]):
invalid = not os.access(v_split[0], os.EX_OK)
elif find_binary(v_split[0]) is None:
invalid = True
return (not invalid, v_split)
def _check_world(self, onProgress):
eroot = portage.settings['EROOT']
self.world_file = os.path.join(eroot, portage.const.WORLD_FILE)
self.found = os.access(self.world_file, os.R_OK)
vardb = portage.db[eroot]["vartree"].dbapi
from portage._sets import SETPREFIX
sets = self._sets
world_atoms = list(sets["selected"])
maxval = len(world_atoms)
if onProgress:
onProgress(maxval, 0)
for i, atom in enumerate(world_atoms):
if not isinstance(atom, portage.dep.Atom):
if atom.startswith(SETPREFIX):
s = atom[len(SETPREFIX):]
if s in sets:
self.okay.append(atom)
else:
self.not_installed.append(atom)
return 1
# as some people use a separate PORTAGE_TMPDIR mount
# we prefer that as the checks below would otherwise be pointless
# for those people.
checkdir = first_existing(os.path.join(settings["PORTAGE_TMPDIR"], "portage"))
if not os.access(checkdir, os.W_OK):
writemsg(_("%s is not writable.\n"
"Likely cause is that you've mounted it as readonly.\n") % checkdir,
noiselevel=-1)
return 1
with tempfile.NamedTemporaryFile(prefix="exectest-", dir=checkdir) as fd:
os.chmod(fd.name, 0o755)
if not os.access(fd.name, os.X_OK):
writemsg(_("Can not execute files in %s\n"
"Likely cause is that you've mounted it with one of the\n"
"following mount options: 'noexec', 'user', 'users'\n\n"
"Please make sure that portage can execute files in this directory.\n") % checkdir,
noiselevel=-1)
return 1
return os.EX_OK
def findLicensePath(self, license_name):
for x in reversed(self.porttrees):
license_path = os.path.join(x, "licenses", license_name)
if os.access(license_path, os.R_OK):
return license_path
return None
def pickle_read(filename, default=None, debug=0):
if not os.access(filename, os.R_OK):
writemsg(_("pickle_read(): File not readable. '") + filename + "'\n", 1)
return default
data = None
try:
myf = open(_unicode_encode(filename,
encoding=_encodings['fs'], errors='strict'), 'rb')
mypickle = pickle.Unpickler(myf)
data = mypickle.load()
myf.close()
del mypickle, myf
writemsg(_("pickle_read(): Loaded pickle. '") + filename + "'\n", 1)
except SystemExit as e:
raise
except Exception as e:
writemsg(_("!!! Failed to load pickle: ") + str(e) + "\n", 1)
data = default