aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNAKAMURA Takumi <geek4civic@gmail.com>2012-05-08 14:31:46 +0000
committerNAKAMURA Takumi <geek4civic@gmail.com>2012-05-08 14:31:46 +0000
commit6781c96599022b8baf03113d7b6f35bd3494b926 (patch)
tree3eaff44e06cc9b70a76bfa867422bb3a118689cd
parenta33701098936ffba12326d96e98d388357f3e098 (diff)
downloadexternal_llvm-6781c96599022b8baf03113d7b6f35bd3494b926.zip
external_llvm-6781c96599022b8baf03113d7b6f35bd3494b926.tar.gz
external_llvm-6781c96599022b8baf03113d7b6f35bd3494b926.tar.bz2
Windows/PathV2.inc: Retry rename() for (maximum) 2 seconds.
Files might be opend by system scanners (eg. file indexer, virus scanner, &c). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156380 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Support/Windows/PathV2.inc18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/Support/Windows/PathV2.inc b/lib/Support/Windows/PathV2.inc
index e9ce5d9..66b8d84 100644
--- a/lib/Support/Windows/PathV2.inc
+++ b/lib/Support/Windows/PathV2.inc
@@ -301,11 +301,21 @@ error_code rename(const Twine &from, const Twine &to) {
if (error_code ec = UTF8ToUTF16(f, wide_from)) return ec;
if (error_code ec = UTF8ToUTF16(t, wide_to)) return ec;
- if (!::MoveFileExW(wide_from.begin(), wide_to.begin(),
- MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING))
- return windows_error(::GetLastError());
+ error_code ec = error_code::success();
+ for (int i = 0; i < 2000; i++) {
+ if (::MoveFileExW(wide_from.begin(), wide_to.begin(),
+ MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING))
+ return error_code::success();
+ ec = windows_error(::GetLastError());
+ if (ec != windows_error::access_denied)
+ break;
+ // Retry MoveFile() at ACCESS_DENIED.
+ // System scanners (eg. indexer) might open the source file when
+ // It is written and closed.
+ ::Sleep(1);
+ }
- return error_code::success();
+ return ec;
}
error_code resize_file(const Twine &path, uint64_t size) {