Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def validate(self):
"""Validate miscellaneous settings and display warnings if necessary.
(This code was previously in the global scope of portage.py)"""
groups = self.get("ACCEPT_KEYWORDS", "").split()
archlist = self.archlist()
if not archlist:
writemsg(_("--- 'profiles/arch.list' is empty or "
"not available. Empty ebuild repository?\n"), noiselevel=1)
else:
for group in groups:
if group not in archlist and \
not (group.startswith("-") and group[1:] in archlist) and \
group not in ("*", "~*", "**"):
writemsg(_("!!! INVALID ACCEPT_KEYWORDS: %s\n") % str(group),
noiselevel=-1)
profile_broken = False
# getmaskingstatus requires ARCH for ACCEPT_KEYWORDS support
arch = self.get('ARCH')
if not self.profile_path or not arch:
profile_broken = True
else:
# If any one of these files exists, then
# the profile is considered valid.
for x in ("make.defaults", "parent",
"packages", "use.force", "use.mask"):
if exists_raise_eaccess(os.path.join(self.profile_path, x)):
break
else:
# start with either 'ro' or 'rw'
# example line:
# 14 1 8:3 / / rw,noatime - ext3 /dev/root rw,errors=continue,commit=5,barrier=1,data=writeback
# _dir ^ ^ attr1 ^ attr2
# there can be a variable number of fields
# to the left of the ' - ', after the attr's, so split it there
mount = line.split(' - ', 1)
_dir, attr1 = mount[0].split()[4:6]
attr2 = mount[1].split()[2]
if attr1.startswith('ro') or attr2.startswith('ro'):
ro_filesystems.add(_dir)
# If /proc/self/mountinfo can't be read, assume that there are no RO
# filesystems and return.
except EnvironmentError:
writemsg_level(_("!!! /proc/self/mountinfo cannot be read"),
level=logging.WARNING, noiselevel=-1)
return []
ro_devs = {}
for x in ro_filesystems:
try:
ro_devs[os.stat(x).st_dev] = x
except OSError:
pass
ro_filesystems.clear()
for x in set(dir_list):
try:
dev = os.stat(x).st_dev
except OSError:
pass
" detected in '%s'\n") % group_name, noiselevel=-1)
rValue.append("@"+group_name)
elif license_group:
traversed_groups.add(group_name)
for l in license_group:
if l.startswith("-"):
writemsg(_("Skipping invalid element %s"
" in license group '%s'\n") % (l, group_name),
noiselevel=-1)
else:
rValue.extend(self._expandLicenseToken(l, traversed_groups))
else:
if self._license_groups and \
group_name not in self._undef_lic_groups:
self._undef_lic_groups.add(group_name)
writemsg(_("Undefined license group '%s'\n") % group_name,
noiselevel=-1)
rValue.append("@"+group_name)
if negate:
rValue = ["-" + token for token in rValue]
return rValue
break
renamefailed = 1
if hardlinked:
renamefailed = False
if not hardlinked and (selinux_enabled or sstat.st_dev == dstat.st_dev):
try:
if selinux_enabled:
selinux.rename(src, dest)
else:
os.rename(src, dest)
renamefailed = 0
except OSError as e:
if e.errno != errno.EXDEV:
# Some random error.
writemsg("!!! %s\n" % _("Failed to move %(src)s to %(dest)s") %
{"src": src, "dest": dest}, noiselevel=-1)
writemsg("!!! %s\n" % (e,), noiselevel=-1)
return None
# Invalid cross-device-link 'bind' mounted or actually Cross-Device
if renamefailed:
if stat.S_ISREG(sstat[stat.ST_MODE]):
dest_tmp = dest + "#new"
dest_tmp_bytes = _unicode_encode(dest_tmp, encoding=encoding,
errors='strict')
try: # For safety copy then move it over.
_copyfile(src_bytes, dest_tmp_bytes)
_apply_stat(sstat, dest_tmp_bytes)
if xattr_enabled:
try:
_copyxattr(src_bytes, dest_tmp_bytes,
exclude=mysettings.get("PORTAGE_XATTR_EXCLUDE", ""))
os.path.dirname(os.path.dirname(pkgdir)))
mf = mf.load_manifest(pkgdir, mysettings["DISTDIR"])
eout = EOutput()
eout.quiet = mysettings.get("PORTAGE_QUIET", None) == "1"
try:
if not mf.thin and strict and "PORTAGE_PARALLEL_FETCHONLY" not in mysettings:
if mf.fhashdict.get("EBUILD"):
eout.ebegin(_("checking ebuild checksums ;-)"))
mf.checkTypeHashes("EBUILD", hash_filter=hash_filter)
eout.eend(0)
if mf.fhashdict.get("AUX"):
eout.ebegin(_("checking auxfile checksums ;-)"))
mf.checkTypeHashes("AUX", hash_filter=hash_filter)
eout.eend(0)
if mf.strict_misc_digests and mf.fhashdict.get("MISC"):
eout.ebegin(_("checking miscfile checksums ;-)"))
mf.checkTypeHashes("MISC", ignoreMissingFiles=True,
hash_filter=hash_filter)
eout.eend(0)
for f in myfiles:
eout.ebegin(_("checking %s ;-)") % f)
ftype = mf.findFile(f)
if ftype is None:
if mf.allow_missing:
continue
eout.eend(1)
writemsg(_("\n!!! Missing digest for '%s'\n") % (f,),
noiselevel=-1)
return 0
mf.checkFileHashes(ftype, f, hash_filter=hash_filter)
eout.eend(0)
except FileNotFound as e:
try:
f = open(_unicode_encode(self._aux_cache_filename,
encoding=_encodings['fs'], errors='strict'),
mode='rb', **open_kwargs)
mypickle = pickle.Unpickler(f)
try:
mypickle.find_global = None
except AttributeError:
# TODO: If py3k, override Unpickler.find_class().
pass
aux_cache = mypickle.load()
f.close()
del f
except (IOError, OSError, EOFError, ValueError, pickle.UnpicklingError) as e:
if isinstance(e, pickle.UnpicklingError):
writemsg(_("!!! Error loading '%s': %s\n") % \
(self._aux_cache_filename, str(e)), noiselevel=-1)
del e
if not aux_cache or \
not isinstance(aux_cache, dict) or \
aux_cache.get("version") != self._aux_cache_version or \
not aux_cache.get("packages"):
aux_cache = {"version": self._aux_cache_version}
aux_cache["packages"] = {}
owners = aux_cache.get("owners")
if owners is not None:
if not isinstance(owners, dict):
owners = None
elif "version" not in owners:
owners = None
except OSError:
pass
make_conf_count = 0
make_conf = {}
for x in make_conf_paths:
mygcfg = getconfig(x,
tolerant=tolerant, allow_sourcing=True,
expand=make_conf, recursive=True)
if mygcfg is not None:
make_conf.update(mygcfg)
make_conf_count += 1
if make_conf_count == 2:
writemsg("!!! %s\n" %
_("Found 2 make.conf files, using both '%s' and '%s'") %
tuple(make_conf_paths), noiselevel=-1)
# Allow ROOT setting to come from make.conf if it's not overridden
# by the constructor argument (from the calling environment).
locations_manager.set_root_override(make_conf.get("ROOT"))
target_root = locations_manager.target_root
eroot = locations_manager.eroot
self.global_config_path = locations_manager.global_config_path
# The expand_map is used for variable substitution
# in getconfig() calls, and the getconfig() calls
# update expand_map with the value of each variable
# assignment that occurs. Variable substitution occurs
# in the following order, which corresponds to the
# order of appearance in self.lookuplist:
#
except NoOptionError:
setname = sname
if setname in self.psets and not update:
self.errors.append(_("Redefinition of set '%s' (sections: '%s', '%s')") % (setname, self.psets[setname].creator, sname))
if hasattr(setclass, "singleBuilder"):
try:
self.psets[setname] = setclass.singleBuilder(optdict, self.settings, self.trees)
self.psets[setname].creator = sname
if parser.has_option(sname, "world-candidate") and \
parser.getboolean(sname, "world-candidate"):
self.psets[setname].world_candidate = True
except SetConfigError as e:
self.errors.append(_("Configuration error in section '%s': %s") % (sname, str(e)))
continue
else:
self.errors.append(_("'%(class)s' does not support individual set creation, section '%(section)s' "
"must be configured as multiset") % {"class": classname, "section": sname})
continue
self._parsed = True
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)
os.system(("cd / ; %s -elf -i " + \
"-f '%svar/run/ld-elf.so.hints' '%setc/ld.so.conf'") % \
(ldconfig, target_root, target_root))
del specials["LDPATH"]
penvnotice = "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\n"
penvnotice += "# DO NOT EDIT THIS FILE. CHANGES TO STARTUP PROFILES\n"
cenvnotice = penvnotice[:]
penvnotice += "# GO INTO /etc/profile NOT /etc/profile.env\n\n"
cenvnotice += "# GO INTO /etc/csh.cshrc NOT /etc/csh.env\n\n"
# in order to conserve memory.
frozensets = {}
owner_entries = collections.defaultdict(list)
while True:
try:
owner, location, l = lines.pop()
except IndexError:
break
l = l.rstrip("\n")
if not l:
continue
if '\0' in l:
# os.stat() will raise "TypeError: must be encoded string
# without NULL bytes, not str" in this case.
writemsg_level(_("\nLine contains null byte(s) " \
"in %s: %s\n\n") % (location, l),
level=logging.ERROR, noiselevel=-1)
continue
try:
entry = NeededEntry.parse(location, l)
except InvalidData as e:
writemsg_level("\n%s\n\n" % (e,),
level=logging.ERROR, noiselevel=-1)
continue
# If NEEDED.ELF.2 contains the new multilib category field,
# then use that for categorization. Otherwise, if a mapping
# exists, map e_machine (entry.arch) to an approximate
# multilib category. If all else fails, use e_machine, just
# as older versions of portage did.
if entry.multilib_category is None: