summaryrefslogtreecommitdiffstats
path: root/pym/portage/update.py
diff options
context:
space:
mode:
Diffstat (limited to 'pym/portage/update.py')
-rw-r--r--pym/portage/update.py46
1 files changed, 39 insertions, 7 deletions
diff --git a/pym/portage/update.py b/pym/portage/update.py
index 121e95720..017f71f62 100644
--- a/pym/portage/update.py
+++ b/pym/portage/update.py
@@ -22,7 +22,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
)
from portage.const import USER_CONFIG_PATH
-from portage.dep import _get_slot_re
+from portage.dep import Atom, _get_slot_re
from portage.eapi import _get_eapi_attrs
from portage.exception import DirectoryNotFound, InvalidAtom, PortageException
from portage.localization import _
@@ -57,12 +57,44 @@ def update_dbentry(update_cmd, mycontent, eapi=None):
return "".join(matchobj.groups())
mycontent = re.sub("(%s-)(\\S*)" % old_value, myreplace, mycontent)
elif update_cmd[0] == "slotmove" and update_cmd[1].operator is None:
- pkg, origslot, newslot = update_cmd[1:]
- old_value = "%s:%s" % (pkg, origslot)
- if old_value in mycontent:
- old_value = re.escape(old_value)
- new_value = "%s:%s" % (pkg, newslot)
- mycontent = re.sub(old_value+"($|\\s)", new_value+"\\1", mycontent)
+ orig_atom, origslot, newslot = update_cmd[1:]
+ orig_cp = orig_atom.cp
+
+ # We don't support versioned slotmove atoms here, since it can be
+ # difficult to determine if the version constraints really match
+ # the atoms that we're trying to update.
+ if orig_atom.version is None and orig_cp in mycontent:
+ # this split preserves existing whitespace
+ split_content = re.split(r'(\s+)', mycontent)
+ modified = False
+ for i, token in enumerate(split_content):
+ if orig_cp not in token:
+ continue
+ try:
+ atom = Atom(token, eapi=eapi)
+ except InvalidAtom:
+ continue
+ if atom.cp != orig_cp:
+ continue
+ if atom.slot is None or atom.slot != origslot:
+ continue
+
+ slot_part = newslot
+ if atom.sub_slot is not None:
+ if atom.sub_slot == origslot:
+ sub_slot = newslot
+ else:
+ sub_slot = atom.sub_slot
+ slot_part += "/" + sub_slot
+ if atom.slot_operator is not None:
+ slot_part += atom.slot_operator
+
+ split_content[i] = atom.with_slot(slot_part)
+ modified = True
+
+ if modified:
+ mycontent = "".join(split_content)
+
return mycontent
def update_dbentries(update_iter, mydata, eapi=None):