diff options
author | Curl Upstream <curl-library@cool.haxx.se> | 2020-08-19 07:37:28 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-08-19 16:44:30 (GMT) |
commit | 7ceb56989f8ab3a4e1b1f2c48c9a0f382b85ec04 (patch) | |
tree | 936c40c921e79b8eabd623181d78167188bbc810 /lib/rename.c | |
parent | 4446fda8e019a0138bec1aa2d83a720d63019ff9 (diff) | |
download | CMake-7ceb56989f8ab3a4e1b1f2c48c9a0f382b85ec04.zip CMake-7ceb56989f8ab3a4e1b1f2c48c9a0f382b85ec04.tar.gz CMake-7ceb56989f8ab3a4e1b1f2c48c9a0f382b85ec04.tar.bz2 |
curl 2020-08-19 (9d954e49)
Code extracted from:
https://github.com/curl/curl.git
at commit 9d954e49bce3706a9a2efb119ecd05767f0f2a9e (curl-7_72_0).
Diffstat (limited to 'lib/rename.c')
-rw-r--r-- | lib/rename.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/rename.c b/lib/rename.c index bb170d3..fe5f95d 100644 --- a/lib/rename.c +++ b/lib/rename.c @@ -27,6 +27,7 @@ #if (!defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)) || \ defined(USE_ALTSVC) +#include "curl_multibyte.h" #include "timeval.h" /* The last 3 #include files should be in this order */ @@ -39,17 +40,25 @@ int Curl_rename(const char *oldpath, const char *newpath) { #ifdef WIN32 /* rename() on Windows doesn't overwrite, so we can't use it here. - MoveFileExA() will overwrite and is usually atomic, however it fails + MoveFileEx() will overwrite and is usually atomic, however it fails when there are open handles to the file. */ const int max_wait_ms = 1000; struct curltime start = Curl_now(); + TCHAR *tchar_oldpath = curlx_convert_UTF8_to_tchar((char *)oldpath); + TCHAR *tchar_newpath = curlx_convert_UTF8_to_tchar((char *)newpath); for(;;) { timediff_t diff; - if(MoveFileExA(oldpath, newpath, MOVEFILE_REPLACE_EXISTING)) + if(MoveFileEx(tchar_oldpath, tchar_newpath, MOVEFILE_REPLACE_EXISTING)) { + curlx_unicodefree(tchar_oldpath); + curlx_unicodefree(tchar_newpath); break; + } diff = Curl_timediff(Curl_now(), start); - if(diff < 0 || diff > max_wait_ms) + if(diff < 0 || diff > max_wait_ms) { + curlx_unicodefree(tchar_oldpath); + curlx_unicodefree(tchar_newpath); return 1; + } Sleep(1); } #else |