Fix _setitem() to write the same format that's currently distributed in the
authorZac Medico <zmedico@gentoo.org>
Tue, 6 Jan 2009 01:01:35 +0000 (01:01 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 6 Jan 2009 01:01:35 +0000 (01:01 -0000)
rsync tree.

svn path=/main/trunk/; revision=12383

pym/portage/cache/metadata.py

index b602f62bc8cc7682fc2636630a53f472ffbf4e9e..8f7992472c2ac65cbd389addf7acc936b1c35bad 100644 (file)
@@ -3,9 +3,9 @@
 # License: GPL2
 # $Id$
 
-import os, re, stat, types
+import errno, os, re
 from portage.cache import cache_errors, flat_hash
-import portage.eclass_cache 
+import portage.eclass_cache
 from portage.cache.template import reconstruct_eclasses
 from portage.cache.mappings import ProtectedDict
 
@@ -74,7 +74,42 @@ class database(flat_hash.database):
 
                return d
 
-
-               
        def _setitem(self, cpv, values):
-               flat_hash.database._setitem(self, cpv, values)
+               if "_eclasses_" in values:
+                       values = ProtectedDict(values)
+                       values["INHERITED"] = ' '.join(sorted(
+                               reconstruct_eclasses(cpv, values["_eclasses_"])))
+
+               s = cpv.rfind("/")
+               fp = os.path.join(self.location,cpv[:s],
+                       ".update.%i.%s" % (os.getpid(), cpv[s+1:]))
+               try:
+                       myf = open(fp, "w")
+               except EnvironmentError, e:
+                       if errno.ENOENT == e.errno:
+                               try:
+                                       self._ensure_dirs(cpv)
+                                       myf = open(fp, "w")
+                               except EnvironmentError, e:
+                                       raise cache_errors.CacheCorruption(cpv, e)
+                       else:
+                               raise cache_errors.CacheCorruption(cpv, e)
+
+               try:
+                       for k in self.auxdbkey_order:
+                               myf.write(values.get(k, "") + "\n")
+                       for i in xrange(magic_line_count - len(self.auxdbkey_order)):
+                               myf.write("\n")
+               finally:
+                       myf.close()
+               self._ensure_access(fp, mtime=values["_mtime_"])
+
+               new_fp = os.path.join(self.location, cpv)
+               try:
+                       os.rename(fp, new_fp)
+               except EnvironmentError, e:
+                       try:
+                               os.unlink(fp)
+                       except EnvironmentError:
+                               pass
+                       raise cache_errors.CacheCorruption(cpv, e)