OSDN Git Service

Fix rename() sometimes failing if another process uses openFileForRead()
authorGreg Bedwell <greg_bedwell@sn.scee.net>
Mon, 12 Oct 2015 15:11:47 +0000 (15:11 +0000)
committerGreg Bedwell <greg_bedwell@sn.scee.net>
Mon, 12 Oct 2015 15:11:47 +0000 (15:11 +0000)
commitd02add1701a126f37332217bbe17356bfa2a9a0f
tree233e3685dbb3b954126f95108b03c1b1ffed88dd
parent40a996d5d23fb2df8f753ba1e67d8578f556f321
Fix rename() sometimes failing if another process uses openFileForRead()

On Windows, fs::rename() could fail is another process was reading the
file at the same time using fs::openFileForRead().  In most cases the user
wouldn't notice as fs::rename() will continue to retry for 2000ms.  Typically
this is enough for the read to complete and a retry to succeed, but if the
disk is being it too hard then the response time might be longer than the
retry time and the rename would fail with a permission error.

Add FILE_SHARE_DELETE to the sharing flags for CreateFileW() in
fs::openFileForRead() and try ReplaceFileW() prior to MoveFileExW()
in fs::rename().

Based on an initial patch by Edd Dawson!

Differential Revision: http://reviews.llvm.org/D13647

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250046 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Support/Windows/Path.inc
unittests/Support/CMakeLists.txt
unittests/Support/ReplaceFileTest.cpp [new file with mode: 0644]