if new_world_atom == sets["world"].findAtomForPackage(pkg_key, metadata):
# Both atoms would be identical, so there's nothing to add.
return None
- if not slotted and sets["system"].findAtomForPackage(pkg_key, metadata):
- return None
+ if not slotted:
+ # Unlike world atoms, system atoms are not greedy for slots, so they
+ # can't be safely excluded from world if they are slotted.
+ system_atom = sets["system"].findAtomForPackage(pkg_key, metadata)
+ if system_atom and \
+ not portage.dep_getkey(system_atom).startswith("virtual/"):
+ # System virtuals aren't safe to exclude from world since they can
+ # match multiple old-style virtuals but only one of them will be
+ # pulled in by update or depclean.
+ return None
return new_world_atom
def filter_iuse_defaults(iuse):