[yum-commits] Branch 'multi-downloader' - urlgrabber/grabber.py

zpavlas at osuosl.org zpavlas at osuosl.org
Wed Feb 1 15:33:39 UTC 2012


 urlgrabber/grabber.py |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

New commits:
commit 8222b4f21c3d359fea064501f39057502e7f2922
Author: Zdeněk Pavlas <zpavlas at redhat.com>
Date:   Wed Feb 1 16:33:20 2012 +0100

    prevent a race on timedhosts file

diff --git a/urlgrabber/grabber.py b/urlgrabber/grabber.py
index 096b7ca..d89da47 100644
--- a/urlgrabber/grabber.py
+++ b/urlgrabber/grabber.py
@@ -2236,10 +2236,13 @@ class _TH:
     def save():
         filename = default_grabber.opts.timedhosts
         if filename and _TH.dirty is True:
+            tmp = '%s.%d' % (filename, os.getpid())
             try:
-                write = open(filename, 'w').write
+                f = open(tmp, 'w')
                 for host in _TH.hosts:
-                    write(host + ' %d %d %d\n' % _TH.hosts[host])
+                    f.write(host + ' %d %d %d\n' % _TH.hosts[host])
+                f.close()
+                os.rename(tmp, filename)
             except IOError: pass
             _TH.dirty = False
 


More information about the Yum-commits mailing list