changeset 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 05800c403321
children a9c15cae50e5
files fetch_command.py
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
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)'