diff fetch_command.py @ 32:d01196ca1e39

Fix non-atomic write of the last_revision_handled_file which was causing problems if the write got interrupted in the wrong spot.
author Augie Fackler <durin42@gmail.com>
date Wed, 15 Oct 2008 13:29:20 -0500
parents 575bd29bc1d8
children a9c15cae50e5
line wrap: on
line diff
--- a/fetch_command.py
+++ b/fetch_command.py
@@ -87,8 +87,12 @@ def fetch_revisions(ui, svn_url, hg_repo
                     else:
                         stupid_svn_server_pull_rev(ui, svn, hg_editor, r)
                     converted = True
-                    open(hg_editor.last_revision_handled_file,
-                         'w').write(str(r.revnum))
+                    tmpfile = '%s_tmp' % hg_editor.last_revision_handled_file
+                    fp = open(tmpfile, 'w')
+                    fp.write(str(r.revnum))
+                    fp.close()
+                    merc_util.rename(tmpfile,
+                                     hg_editor.last_revision_handled_file)
                 except core.SubversionException, e:
                     if hasattr(e, 'message') and (
                         'Server sent unexpected return value (502 Bad Gateway)'