Make WorldHandler lock the world file when in --fix mode.
authorZac Medico <zmedico@gentoo.org>
Mon, 5 Nov 2007 08:41:00 +0000 (08:41 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 5 Nov 2007 08:41:00 +0000 (08:41 -0000)
svn path=/main/trunk/; revision=8432

bin/emaint
pym/portage/sets/base.py

index 66a4dddf995199a0bcef16944469235848b93e1b..bfce4fc96525439be3247ad87e54ebdc9288cb9e 100755 (executable)
@@ -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):
 
index 85f2e410b64a31af6f76cf7a8f01fa605fb9baf3..f360632ede3f3ef4e0fc583fa17751883f167679 100644 (file)
@@ -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)