[Updated] D11250: testing: make sure write_file is "atomic"

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Thu Aug 5 09:14:04 UTC 2021


Closed by commit rHG5ad37164a8fe: testing: make sure write_file is "atomic" (authored by marmoute).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D11250?vs=29787&id=29801

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D11250/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D11250

AFFECTED FILES
  mercurial/testing/__init__.py

CHANGE DETAILS

diff --git a/mercurial/testing/__init__.py b/mercurial/testing/__init__.py
--- a/mercurial/testing/__init__.py
+++ b/mercurial/testing/__init__.py
@@ -33,5 +33,11 @@
 
 
 def write_file(path, content=b''):
-    with open(path, 'wb') as f:
+    if content:
+        write_path = b'%s.tmp' % path
+    else:
+        write_path = path
+    with open(write_path, 'wb') as f:
         f.write(content)
+    if path != write_path:
+        os.rename(write_path, path)



To: marmoute, #hg-reviewers, Alphare
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20210805/33e32343/attachment-0002.html>


More information about the Mercurial-patches mailing list