summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2012-09-19 21:08:47 -0700
committerZac Medico <zmedico@gentoo.org>2012-09-19 21:08:47 -0700
commitcc13d56d9f13e518eefd6ba67364d73ac464f184 (patch)
tree363502d71670badd53c87453e1ae79344885898a
parent6033efa29268178cb7b2343b1d18888ce1c42266 (diff)
downloadportage-cc13d56d9f13e518eefd6ba67364d73ac464f184.tar.gz
portage-cc13d56d9f13e518eefd6ba67364d73ac464f184.tar.bz2
portage-cc13d56d9f13e518eefd6ba67364d73ac464f184.zip
update_dbentry: fix "move" to translate atom[use]
-rw-r--r--pym/portage/tests/update/test_update_dbentry.py3
-rw-r--r--pym/portage/update.py31
2 files changed, 22 insertions, 12 deletions
diff --git a/pym/portage/tests/update/test_update_dbentry.py b/pym/portage/tests/update/test_update_dbentry.py
index 406331809..cb69053f7 100644
--- a/pym/portage/tests/update/test_update_dbentry.py
+++ b/pym/portage/tests/update/test_update_dbentry.py
@@ -24,6 +24,9 @@ class UpdateDbentryTestCase(TestCase):
(("move", Atom("dev-libs/A"), Atom("dev-libs/B")), "1",
" >=dev-libs/A-1:0 ", " >=dev-libs/B-1:0 "),
+ (("move", Atom("dev-libs/A"), Atom("dev-libs/B")), "2",
+ " dev-libs/A[foo] ", " dev-libs/B[foo] "),
+
(("move", Atom("dev-libs/A"), Atom("dev-libs/B")), "5_pre2",
" dev-libs/A:0/1=[foo] ", " dev-libs/B:0/1=[foo] "),
diff --git a/pym/portage/update.py b/pym/portage/update.py
index 017f71f62..fe00b7e35 100644
--- a/pym/portage/update.py
+++ b/pym/portage/update.py
@@ -44,18 +44,25 @@ def update_dbentry(update_cmd, mycontent, eapi=None):
# Use isvalidatom() to check if this move is valid for the
# EAPI (characters allowed in package names may vary).
if old_value in mycontent and isvalidatom(new_value, eapi=eapi):
- old_value = re.escape(old_value);
- mycontent = re.sub(old_value+"(:|$|\\s)", new_value+"\\1", mycontent)
- def myreplace(matchobj):
- # Strip slot and * operator if necessary
- # so that ververify works.
- ver = remove_slot(matchobj.group(2))
- ver = ver.rstrip("*")
- if ververify(ver):
- return "%s-%s" % (new_value, matchobj.group(2))
- else:
- return "".join(matchobj.groups())
- mycontent = re.sub("(%s-)(\\S*)" % old_value, myreplace, mycontent)
+ # this split preserves existing whitespace
+ split_content = re.split(r'(\s+)', mycontent)
+ modified = False
+ for i, token in enumerate(split_content):
+ if old_value not in token:
+ continue
+ try:
+ atom = Atom(token, eapi=eapi)
+ except InvalidAtom:
+ continue
+ if atom.cp != old_value:
+ continue
+
+ split_content[i] = token.replace(old_value, new_value, 1)
+ modified = True
+
+ if modified:
+ mycontent = "".join(split_content)
+
elif update_cmd[0] == "slotmove" and update_cmd[1].operator is None:
orig_atom, origslot, newslot = update_cmd[1:]
orig_cp = orig_atom.cp