From 8d307879cf8ff7c6b66755dd5ff7e7d6df994d97 Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Fri, 12 Jan 2007 22:54:13 +0000 Subject: [PATCH] Merged from trunk 5565:5581 add some invalid ops to getcpv to make sure it returns the cpv still (WarnerBro) print the incorrect atom (WarnerBro) Valid categories in catpkgsplit (WarnerBro) catch and validate new ValueError Exception (WarnerBro) Fix comments for catpkgsplit (WarnerBro) Handle the exception in isvalidatom, change it to use a portage exceptoin, thanks to Zac for pointing this out (WarnerBro) learn to spell (WarnerBro) SpanKY likes the latin categories (WarnerBro) Use a global to ensure that the valid_category regex is cached. dont compress files that are already compressed and dont do sanity checking on the link dest as we cant properly verify things like absolute symlinks (SpankMan) use cached suffix value and if it is not valid, lets warn (SpankMan) Allow catpkgsplit to be less strict for atoms that come from installed packages (for backward compatibility). Fix ebuild environment color.map support so that it works properly through exec calls (since the color variables can not be directly exported due to env pollution). drop lazy bindings check once and for all ... the system ldso should have the logic #71609 (SpankMan) For bug #147512, don't print a cryptic error message when an EnvironmentError occurs. Also, allow the user to get a traceback via --debug. Change vercmp to use int() instead of string atoi, catch ValueError in pkgcmp (WarnerBro) svn path=/main/branches/prefix/; revision=5618 --- bin/ecompressdir | 16 +++++------- bin/emerge | 2 ++ bin/isolated-functions.sh | 16 +++++++----- bin/misc-functions.sh | 14 ---------- pym/portage.py | 37 +++++++++++++++++++-------- pym/portage_dep.py | 10 +++++--- pym/portage_versions.py | 32 ++++++++++++++++++++--- tests/portage_dep/test_dep_getcpv.py | 6 +++++ tests/portage_dep/test_isvalidatom.py | 4 +-- 9 files changed, 86 insertions(+), 51 deletions(-) diff --git a/bin/ecompressdir b/bin/ecompressdir index 405f8e2f5..3f6fb251e 100755 --- a/bin/ecompressdir +++ b/bin/ecompressdir @@ -10,7 +10,10 @@ fi # figure out the new suffix suffix=$(ecompress --suffix) -[[ -z ${suffix} ]] && exit 0 +if [[ -z ${suffix} ]] ; then + vecho "${0##*/}: unable to figure out compressed suffix" + exit 1 +fi source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh @@ -25,19 +28,14 @@ for dir in "$@" ; do vecho "${0##*/}: $(ecompress --bin) ${dir#${D}}" fi - find "${dir}" -type f -print0 | xargs -0 ecompress + find "${dir}" -type f '!' -name '*'${suffix} -print0 | xargs -0 ecompress ((ret+=$?)) find -L "${dir}" -type l | \ while read brokenlink ; do olddest=$(readlink "${brokenlink}") newdest="${olddest}${suffix}" - if [[ -e ${newdest} ]] ; then - ln -snf "${newdest}" "${brokenlink}" - ((ret+=$?)) - else - vecho "ecompressdir: unknown broken symlink: ${brokenlink}" - ((++ret)) - fi + ln -snf "${newdest}" "${brokenlink}" + ((ret+=$?)) done done diff --git a/bin/emerge b/bin/emerge index 75d4cb721..5eec86e18 100755 --- a/bin/emerge +++ b/bin/emerge @@ -4991,6 +4991,8 @@ def emerge_main(): # together with EMERGE_DEFAULT_OPTS (which may vary depending on the # the value of --config-root). myaction, myopts, myfiles = parse_opts(sys.argv[1:], silent=True) + if "--debug" in myopts: + os.environ["PORTAGE_DEBUG"] = "1" if "--config-root" in myopts: os.environ["PORTAGE_CONFIGROOT"] = myopts["--config-root"] diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh index 25ef146a1..1862d87b0 100644 --- a/bin/isolated-functions.sh +++ b/bin/isolated-functions.sh @@ -211,16 +211,18 @@ set_colors() { ENDCOL=$'\e[A\e['${COLS}'C' # Now, ${ENDCOL} will move us to the end of the # column; irregardless of character width - - [ -z "${GOOD}" ] && GOOD=$'\e[32;01m' - [ -z "${WARN}" ] && WARN=$'\e[33;01m' - [ -z "${BAD}" ] && BAD=$'\e[31;01m' - [ -z "${HILITE}" ] && HILITE=$'\e[36;01m' - [ -z "${BRACKET}" ] && BRACKET=$'\e[34;01m' + if [ -n "${PORTAGE_COLORMAP}" ] ; then + eval ${PORTAGE_COLORMAP} + else + GOOD=$'\e[32;01m' + WARN=$'\e[33;01m' + BAD=$'\e[31;01m' + HILITE=$'\e[36;01m' + BRACKET=$'\e[34;01m' + fi NORMAL=$'\e[0m' } -export -n GOOD WARN BAD HILITE BRACKET RC_ENDCOL="yes" RC_INDENTATION='' RC_DEFAULT_INDENT=2 diff --git a/bin/misc-functions.sh b/bin/misc-functions.sh index cdc2eb7a3..3a4931787 100644 --- a/bin/misc-functions.sh +++ b/bin/misc-functions.sh @@ -95,20 +95,6 @@ install_qa_check() { fi fi - # Check for setid binaries but are not built with BIND_NOW - f=$(scanelf -qyRF '%b %p' "${ED}") - if [[ -n ${f} ]] ; then - vecho -ne '\a\n' - eqawarn "QA Notice: The following files are setXid, dyn linked, and using lazy bindings" - eqawarn " This combination is generally discouraged. Try re-emerging the package:" - eqawarn " LDFLAGS='-Wl,-z,now' emerge ${PN}" - eqawarn "${f}" - vecho -ne '\a\n' - # Do not fail here until we have sorted out the lazy issues with security team - #die_msg="${die_msg} setXid lazy bindings," - sleep 1 - fi - # TEXTREL's are baaaaaaaad # Allow devs to mark things as ignorable ... e.g. things that are # binary-only and upstream isn't cooperating (nvidia-glx) ... we diff --git a/pym/portage.py b/pym/portage.py index 5416f924f..ea43e5d64 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -895,6 +895,8 @@ class config: @type local_config: Boolean """ + debug = os.environ.get("PORTAGE_DEBUG") == "1" + self.already_in_regenerate = 0 self.locked = 0 @@ -1134,9 +1136,12 @@ class config: except SystemExit, e: raise except Exception, e: + if debug: + raise writemsg("!!! %s\n" % (e), noiselevel=-1) - writemsg("!!! Incorrect multiline literals can cause this. Do not use them.\n", noiselevel=-1) - writemsg("!!! Errors in this file should be reported on bugs.gentoo.org.\n") + if not isinstance(e, EnvironmentError): + writemsg("!!! Incorrect multiline literals can cause " + \ + "this. Do not use them.\n", noiselevel=-1) sys.exit(1) self.configlist.append(self.mygcfg) self.configdict["globals"]=self.configlist[-1] @@ -1158,13 +1163,18 @@ class config: except SystemExit, e: raise except Exception, e: + if debug: + raise writemsg("!!! %s\n" % (e), noiselevel=-1) - writemsg("!!! 'rm -Rf %s/usr/portage/profiles; emerge sync' may fix this. If it does\n" % EPREFIX, - noiselevel=-1) - writemsg("!!! not then please report this to bugs.gentoo.org and, if possible, a dev\n", - noiselevel=-1) - writemsg("!!! on #gentoo (irc.freenode.org)\n", - noiselevel=-1) + if not isinstance(e, EnvironmentError): + writemsg("!!! 'rm -Rf %s/usr/portage/profiles; " + \ + "emerge sync' may fix this. If it does\n" % EPREFIX, + noiselevel=-1) + writemsg("!!! not then please report this to " + \ + "bugs.gentoo.org and, if possible, a dev\n", + noiselevel=-1) + writemsg("!!! on #gentoo (irc.freenode.org)\n", + noiselevel=-1) sys.exit(1) self.configlist.append(self.mygcfg) self.configdict["defaults"]=self.configlist[-1] @@ -1178,9 +1188,12 @@ class config: except SystemExit, e: raise except Exception, e: + if debug: + raise writemsg("!!! %s\n" % (e), noiselevel=-1) - writemsg("!!! Incorrect multiline literals can cause this. Do not use them.\n", - noiselevel=-1) + if not isinstance(e, EnvironmentError): + writemsg("!!! Incorrect multiline literals can cause " + \ + "this. Do not use them.\n", noiselevel=-1) sys.exit(1) # Allow ROOT setting to come from make.conf if it's not overridden @@ -2983,8 +2996,10 @@ def doebuild_environment(myebuild, mydo, myroot, mysettings, debug, use_cache, m mysettings["KVERS"]=myso[1] # Allow color.map to control colors associated with einfo, ewarn, etc... + mycolors = [] for c in ("GOOD", "WARN", "BAD", "HILITE", "BRACKET"): - mysettings[c] = output.codes[c] + mycolors.append("%s=$'%s'" % (c, output.codes[c])) + mysettings["PORTAGE_COLORMAP"] = "\n".join(mycolors) def prepare_build_dirs(myroot, mysettings, cleanup): diff --git a/pym/portage_dep.py b/pym/portage_dep.py index 545884409..f6131cc47 100644 --- a/pym/portage_dep.py +++ b/pym/portage_dep.py @@ -20,6 +20,7 @@ import re, string, sys, types import portage_exception +from portage_exception import InvalidData from portage_versions import catpkgsplit, catsplit, pkgcmp, pkgsplit, ververify def cpvequal(cpv1, cpv2): @@ -359,7 +360,10 @@ def isvalidatom(atom, allow_blockers=False): return 0 if allow_blockers and atom.startswith("!"): atom = atom[1:] - mycpv_cps = catpkgsplit(dep_getcpv(atom)) + try: + mycpv_cps = catpkgsplit(dep_getcpv(atom)) + except InvalidData: + return 0 operator = get_operator(atom) if operator: if operator[0] in "<>" and atom[-1] == "*": @@ -614,9 +618,7 @@ def match_from_list(mydep, candidate_list): for x in candidate_list: try: result = pkgcmp(pkgsplit(x), mysplit) - except SystemExit: - raise - except: + except ValueError: writemsg("\nInvalid package name: %s\n" % x, noiselevel=-1) raise if result is None: diff --git a/pym/portage_versions.py b/pym/portage_versions.py index ba46dd6ec..16073ba7a 100644 --- a/pym/portage_versions.py +++ b/pym/portage_versions.py @@ -11,6 +11,7 @@ suffix_regexp = re.compile("^(alpha|beta|rc|pre|p)(\\d*)$") suffix_value = {"pre": -2, "p": 0, "alpha": -4, "beta": -3, "rc": -1} endversion_keys = ["pre", "p", "alpha", "beta", "rc"] +from portage_exception import InvalidData def ververify(myver, silent=1): if ver_regexp.match(myver): @@ -75,9 +76,9 @@ def vercmp(ver1, ver2, silent=1): # building lists of the version parts before the suffix # first part is simple - list1 = [string.atoi(match1.group(2))] - list2 = [string.atoi(match2.group(2))] - + list1 = [int(match1.group(2))] + list2 = [int(match2.group(2))] + # this part would greatly benefit from a fixed-length version pattern if len(match1.group(3)) or len(match2.group(3)): vlist1 = match1.group(3)[1:].split(".") @@ -262,9 +263,29 @@ def pkgsplit(mypkg,silent=1): pkgcache[mypkg]=None return None +_valid_category = re.compile("^\w[\w-]*") + catcache={} def catpkgsplit(mydata,silent=1): - "returns [cat, pkgname, version, rev ]" + """ + Takes a Category/Package-Version-Rev and returns a list of each. + + @param mydata: Data to split + @type mydata: string + @param silent: suppress error messages + @type silent: Boolean (integer) + @rype: list + @return: + 1. If each exists, it returns [cat, pkgname, version, rev] + 2. If cat is not specificed in mydata, cat will be "null" + 3. if rev does not exist it will be '-r0' + 4. If cat is invalid (specified but has incorrect syntax) + an InvalidData Exception will be thrown + """ + + # Categories may contain a-zA-z0-9+_- but cannot start with - + global _valid_category + import portage_dep try: if not catcache[mydata]: return None @@ -277,6 +298,9 @@ def catpkgsplit(mydata,silent=1): retval=["null"] p_split=pkgsplit(mydata,silent=silent) elif len(mysplit)==2: + if portage_dep._dep_check_strict and \ + not _valid_category.match(mysplit[0]): + raise InvalidData("Invalid category in %s" %mydata ) retval=[mysplit[0]] p_split=pkgsplit(mysplit[1],silent=silent) if not p_split: diff --git a/tests/portage_dep/test_dep_getcpv.py b/tests/portage_dep/test_dep_getcpv.py index 6928794a4..90e1b6e56 100644 --- a/tests/portage_dep/test_dep_getcpv.py +++ b/tests/portage_dep/test_dep_getcpv.py @@ -14,6 +14,8 @@ class DepGetCPV(TestCase): prefix_ops = ["<", ">", "=", "~", "!", "<=", ">=", "!=", "!<", "!>", "!~",""] + + bad_prefix_ops = [ ">~", "<~", "~>", "~<" ] postfix_ops = [ "*", "" ] cpvs = ["sys-apps/portage"] @@ -23,3 +25,7 @@ class DepGetCPV(TestCase): for postfix in postfix_ops: self.assertEqual( dep_getcpv( prefix + cpv + postfix ), cpv ) + for prefix in bad_prefix_ops: + for postfix in postfix_ops: + self.assertNotEqual( dep_getcpv( + prefix + cpv + postfix ), cpv ) diff --git a/tests/portage_dep/test_isvalidatom.py b/tests/portage_dep/test_isvalidatom.py index 84225fa78..7835fbd0c 100644 --- a/tests/portage_dep/test_isvalidatom.py +++ b/tests/portage_dep/test_isvalidatom.py @@ -32,5 +32,5 @@ class IsValidAtom(TestCase): atom_type = "valid" else: atom_type = "invalid" - - self.assertEqual( bool(isvalidatom( test[0] )), test[1] ) + self.assertEqual( bool(isvalidatom( test[0] )), test[1], + msg="isvalidatom(%s) != %s" % ( test[0], test[1] ) ) -- 2.26.2