From 88fbc4e6eedf7c1473e0d4fb70af3aa95e75fdeb Mon Sep 17 00:00:00 2001 From: Kostia Balytskyi Date: Tue, 8 May 2018 03:10:31 -0700 Subject: [PATCH] windows: fsync a temporary lock file before renaming it Summary: This helps to avoid the following problem: 1. hg creates a temporary lock file, writes some stuff there 2. os writes this stuff into its buffer 3. hg closes the file, the metadata is written out (or journaled) 4. hg renames the file, which is again a metadata-only operation 5. the buffer is still not flushed 6. the OS crashes 7. upon reload, the os has a file with a correct name and a correct length, but unexpected contents Reviewed By: quark-zju Differential Revision: D7889111 fbshipit-source-id: a0a152c9e7efef34847fa2d2ab9b94191bde43f4 --- mercurial/windows.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mercurial/windows.py b/mercurial/windows.py index 70d5de949e..52f9718098 100644 --- a/mercurial/windows.py +++ b/mercurial/windows.py @@ -531,6 +531,7 @@ def makelock(info, pathname): prefix='%s.%i.' % (basename, os.getpid()), dir=dirname) os.write(fd, info) + os.fsync(fd) os.close(fd) try: os.rename(tname, pathname)