From: Zac Medico Date: Mon, 5 Nov 2007 08:41:00 +0000 (-0000) Subject: Make WorldHandler lock the world file when in --fix mode. X-Git-Tag: v2.2_pre1~438 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f291576504956169153005d0b227b5983c0ba76a;p=portage.git Make WorldHandler lock the world file when in --fix mode. svn path=/main/trunk/; revision=8432 --- diff --git a/bin/emaint b/bin/emaint index 66a4dddf9..bfce4fc96 100755 --- a/bin/emaint +++ b/bin/emaint @@ -24,6 +24,10 @@ class WorldHandler(object): self.not_installed = [] self.invalid_category = [] self.okay = [] + from portage.sets import make_default_config + setconfig = make_default_config(portage.settings, + portage.db[portage.settings["ROOT"]]) + self._sets = setconfig.getSetsWithAliases() def _check_world(self, onProgress): categories = set(portage.settings.categories) @@ -32,10 +36,9 @@ class WorldHandler(object): self.found = os.access(self.world_file, os.R_OK) vardb = portage.db[myroot]["vartree"].dbapi - from portage.sets import make_default_config, SETPREFIX - setconfig = make_default_config(portage.settings, portage.db[myroot]) - sets = setconfig.getSetsWithAliases() - world_atoms = open(self.world_file).read().split() + from portage.sets import SETPREFIX + sets = self._sets + world_atoms = list(sets["world"]) maxval = len(world_atoms) if onProgress: onProgress(maxval, 0) @@ -77,14 +80,23 @@ class WorldHandler(object): return errors def fix(self, onProgress=None): - self._check_world(onProgress) - errors = [] + world_set = self._sets["world"] + world_set.lock() try: - portage.write_atomic(self.world_file, - "\n".join(sorted(self.okay)) + "\n") - except portage.exception.PortageException: - errors.append(self.world_file + " could not be opened for writing") - return errors + world_set.load() # maybe it's changed on disk + before = set(world_set) + self._check_world(onProgress) + after = set(self.okay) + errors = [] + if before != after: + try: + world_set.replace(self.okay) + except portage.exception.PortageException: + errors.append("%s could not be opened for writing" % \ + self.world_file) + return errors + finally: + world_set.unlock() class BinhostHandler(object): diff --git a/pym/portage/sets/base.py b/pym/portage/sets/base.py index 85f2e410b..f360632ed 100644 --- a/pym/portage/sets/base.py +++ b/pym/portage/sets/base.py @@ -58,7 +58,7 @@ class PackageSet(object): def _setAtoms(self, atoms): atoms = map(str.strip, atoms) - nonatoms = set() + self._nonatoms.clear() for a in atoms[:]: if a == "": atoms.remove(a)