Commits

Yuya Nishihara committed ef778af

wconfig: disable atomic rename due to possible unlink/rename race on Windows

Though I don't know if it was caused by our QFileSystemWatcher or a virus
scanner, there are several reports saying util.rename() failed at util.unlink
or os.rename on Windows. So using atomictempfile might not be always safer
than normal file operation on Windows.

https://bitbucket.org/tortoisehg/thg/issues?q=in+rename
https://bitbucket.org/tortoisehg/thg/issue/2286/

Recent TortoiseHg version disables the watcher while running Mercurial commands
in its thread, but it isn't easy to disable the watcher while saving config
file. Config file isn't large, so there would be little risk to read half-
written data.

This also fixes #2181, the NTFS symlink issue.

  • Participants
  • Parent commits 04d7338
  • Branches stable

Comments (0)

Files changed (1)

File tortoisehg/util/wconfig.py

     config.write(buf)
     data = '\n'.join(buf.getvalue().splitlines()) + '\n'
 
-    f = util.atomictempfile(os.path.realpath(path), 'w')
+    if os.name == 'nt':
+        # no atomic rename to the existing file that may fail occasionally
+        # for unknown reasons, possibly because of our QFileSystemWatcher or
+        # a virus scanner.  also it breaks NTFS symlink (issue #2181).
+        openfile = util.posixfile
+    else:
+        # atomic rename is reliable on Unix
+        openfile = util.atomictempfile
+    f = openfile(os.path.realpath(path), 'w')
     try:
         f.write(data)
         f.close()