createrepo/yumbased.py

[email protected] (James Antill)
Newsgroups gmane.linux.rpm.metadata
Message-ID <[email protected]>
 createrepo/yumbased.py |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

New commits:
commit d88de04e301cbe5383e88505ea133f07a659fcbd
Author: James Antill <[email protected]>
Date:   Wed Oct 8 12:42:24 2008 -0400

    Fix parallel updates to the cachedir, thx to Michael Schwendt for spotting it

diff --git a/createrepo/yumbased.py b/createrepo/yumbased.py
index adb6017..3cd0cfe 100644
--- a/createrepo/yumbased.py
+++ b/createrepo/yumbased.py
@@ -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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.