Fix parallel updates to the cachedir, thx to Michael Schwendt for spotting it
authorJames Antill <james@and.org>
Wed, 8 Oct 2008 16:42:24 +0000 (12:42 -0400)
committerJames Antill <james@and.org>
Wed, 8 Oct 2008 16:42:24 +0000 (12:42 -0400)
createrepo/yumbased.py

index adb601722b41396f2f59c8c4c9d4a2077f298060..3cd0cfef692a97fdabf964f44a22c17b0c60a70e 100644 (file)
@@ -28,6 +28,7 @@ from yum.sqlutils import executeSQL
 from rpmUtils.transaction import initReadOnlyTransaction
 from rpmUtils.miscutils import flagToString, stringToVersion
 import utils
+import tempfile
 
 class CreateRepoPackage(YumLocalPackage):
     def __init__(self, ts, package):
@@ -72,9 +73,13 @@ class CreateRepoPackage(YumLocalPackage):
              
         else:
             checksum = misc.checksum('sha', self.localpath)
-            csumo = open(csumfile, 'w')
+
+            #  This is atomic cache creation via. rename, so we can have two
+            # tasks using the same cachedir ... mash does this.
+            csumo = tempfile.NamedTemporaryFile(mode='w', dir=self.crp_cachedir)
             csumo.write(checksum)
             csumo.close()
+            os.rename(csumo.name, csumfile)
         
         self._checksum = checksum