From: James Antill Date: Wed, 8 Oct 2008 16:42:24 +0000 (-0400) Subject: Fix parallel updates to the cachedir, thx to Michael Schwendt for spotting it X-Git-Tag: upstream/0.9.9~100^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d88de04e301cbe5383e88505ea133f07a659fcbd;p=tools%2Fcreaterepo.git 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