[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnurl] 22/173: tool_operate: Fix --remote-time incorrect t
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnurl] 22/173: tool_operate: Fix --remote-time incorrect times on Windows |
Date: |
Fri, 24 Feb 2017 14:00:44 +0100 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to annotated tag gnurl-7.53.1
in repository gnurl.
commit ee3c83f39c90126cabb9be896931725c32f22e09
Author: Jay Satiro <address@hidden>
AuthorDate: Fri Nov 11 02:48:52 2016 -0500
tool_operate: Fix --remote-time incorrect times on Windows
- Use Windows API SetFileTime to set the file time instead of utime.
Avoid utime on Windows if possible because it may apply a daylight
saving time offset to our UTC file time.
Bug: https://curl.haxx.se/mail/archive-2016-11/0033.html
Reported-by: Tim
Closes https://github.com/curl/curl/pull/1121
---
docs/FAQ | 10 ++++++----
src/tool_operate.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 54 insertions(+), 7 deletions(-)
diff --git a/docs/FAQ b/docs/FAQ
index d663811a2..9157022a2 100644
--- a/docs/FAQ
+++ b/docs/FAQ
@@ -1016,10 +1016,12 @@ FAQ
4.13 Why is curl -R on Windows one hour off?
- During daylight savings time, when -R is used, curl will set a time that
- appears one hour off. This happens due to a flaw in how Windows stores and
- uses file modification times and it is not easily worked around. For details
- on this problem, read this: http://www.codeproject.com/datetime/dstbugs.asp
+ Since curl 7.53.0 this issue should be fixed as long as curl was built with
+ any modern compiler that allows for a 64-bit curl_off_t type. For older
+ compilers or prior curl versions it may set a time that appears one hour off.
+ This happens due to a flaw in how Windows stores and uses file modification
+ times and it is not easily worked around. For more details read this:
+ http://www.codeproject.com/datetime/dstbugs.asp
4.14 Redirects work in browser but not with curl!
diff --git a/src/tool_operate.c b/src/tool_operate.c
index 26662aec5..4fa32bcf3 100644
--- a/src/tool_operate.c
+++ b/src/tool_operate.c
@@ -1727,20 +1727,65 @@ static CURLcode operate_do(struct GlobalConfig *global,
}
#endif
-#ifdef HAVE_UTIME
+#if defined(HAVE_UTIME) || \
+ (defined(WIN32) && (CURL_SIZEOF_CURL_OFF_T >= 8))
/* File time can only be set _after_ the file has been closed */
if(!result && config->remote_time && outs.s_isreg && outs.filename) {
/* Ask libcurl if we got a remote file time */
long filetime = -1;
curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
if(filetime >= 0) {
+/* Windows utime() may attempt to adjust our unix gmt 'filetime' by a daylight
+ saving time offset and since it's GMT that is bad behavior. When we have
+ access to a 64-bit type we can bypass utime and set the times directly. */
+#if defined(WIN32) && (CURL_SIZEOF_CURL_OFF_T >= 8)
+ /* 910670515199 is the maximum unix filetime that can be used as a
+ Windows FILETIME without overflow: 30827-12-31T23:59:59. */
+ if(filetime <= CURL_OFF_T_C(910670515199)) {
+ HANDLE hfile = CreateFileA(outs.filename, FILE_WRITE_ATTRIBUTES,
+ (FILE_SHARE_READ | FILE_SHARE_WRITE |
+ FILE_SHARE_DELETE),
+ NULL, OPEN_EXISTING, 0, NULL);
+ if(hfile != INVALID_HANDLE_VALUE) {
+ curl_off_t converted = ((curl_off_t)filetime * 10000000) +
+ CURL_OFF_T_C(116444736000000000);
+ FILETIME ft;
+ ft.dwLowDateTime = (DWORD)(converted & 0xFFFFFFFF);
+ ft.dwHighDateTime = (DWORD)(converted >> 32);
+ if(!SetFileTime(hfile, NULL, &ft, &ft)) {
+ fprintf(config->global->errors,
+ "Failed to set filetime %ld on outfile: "
+ "SetFileTime failed: GetLastError %u\n",
+ filetime, GetLastError());
+ }
+ CloseHandle(hfile);
+ }
+ else {
+ fprintf(config->global->errors,
+ "Failed to set filetime %ld on outfile: "
+ "CreateFile failed: GetLastError %u\n",
+ filetime, GetLastError());
+ }
+ }
+ else {
+ fprintf(config->global->errors,
+ "Failed to set filetime %ld on outfile: overflow\n",
+ filetime);
+ }
+#elif defined(HAVE_UTIME)
struct utimbuf times;
times.actime = (time_t)filetime;
times.modtime = (time_t)filetime;
- utime(outs.filename, ×); /* set the time we got */
+ if(utime(outs.filename, ×)) {
+ fprintf(config->global->errors,
+ "Failed to set filetime %ld on outfile: errno %d\n",
+ filetime, errno);
+ }
+#endif
}
}
-#endif
+#endif /* defined(HAVE_UTIME) || \
+ (defined(WIN32) && (CURL_SIZEOF_CURL_OFF_T >= 8)) */
#ifdef USE_METALINK
if(!metalink && config->use_metalink && result == CURLE_OK) {
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnurl] 27/173: darwinssl: --insecure overrides --cacert if both settings are in use, (continued)
- [GNUnet-SVN] [gnurl] 27/173: darwinssl: --insecure overrides --cacert if both settings are in use, gnunet, 2017/02/24
- [GNUnet-SVN] [gnurl] 32/173: docs/page-header: mention how to disable the progress meter, gnunet, 2017/02/24
- [GNUnet-SVN] [gnurl] 29/173: CIPHERS.md: document GSKit ciphers, gnunet, 2017/02/24
- [GNUnet-SVN] [gnurl] 15/173: RELEASE-NOTES: synced with a7b38c9dc98481e, gnunet, 2017/02/24
- [GNUnet-SVN] [gnurl] 33/173: docs/silent: mention --show-error in --silent description, gnunet, 2017/02/24
- [GNUnet-SVN] [gnurl] 37/173: asiohiper: improved socket handling, gnunet, 2017/02/24
- [GNUnet-SVN] [gnurl] 39/173: RELEASE-NOTES: synced with a41e8592d6b3e58, gnunet, 2017/02/24
- [GNUnet-SVN] [gnurl] 13/173: docs/ciphers: link to our own new page about ciphers, gnunet, 2017/02/24
- [GNUnet-SVN] [gnurl] 31/173: wolfssl: display negotiated SSL version and cipher, gnunet, 2017/02/24
- [GNUnet-SVN] [gnurl] 28/173: TheArtOfHttpScripting: grammar, gnunet, 2017/02/24
- [GNUnet-SVN] [gnurl] 22/173: tool_operate: Fix --remote-time incorrect times on Windows,
gnunet <=
- [GNUnet-SVN] [gnurl] 19/173: cmake: use crypt32.lib when building with OpenSSL on windows, gnunet, 2017/02/24
- [GNUnet-SVN] [gnurl] 26/173: docs/libcurl: TCP_KEEPALIVE start and interval default to 60, gnunet, 2017/02/24
- [GNUnet-SVN] [gnurl] 20/173: curl_formadd.3: CURLFORM_CONTENTSLENGTH not needed when chunked, gnunet, 2017/02/24
- [GNUnet-SVN] [gnurl] 53/173: IDN: Fix compile time detection of linidn2 TR46, gnunet, 2017/02/24
- [GNUnet-SVN] [gnurl] 58/173: curl: reset the easy handle at --next, gnunet, 2017/02/24
- [GNUnet-SVN] [gnurl] 42/173: http2_send: avoid unsigned integer wrap around, gnunet, 2017/02/24
- [GNUnet-SVN] [gnurl] 69/173: http: print correct HTTP string in verbose output when using HTTP/2, gnunet, 2017/02/24
- [GNUnet-SVN] [gnurl] 43/173: smtp: Fix STARTTLS denied error message, gnunet, 2017/02/24
- [GNUnet-SVN] [gnurl] 36/173: lib506: fix build for Open Watcom, gnunet, 2017/02/24
- [GNUnet-SVN] [gnurl] 38/173: examples: make the C++ examples follow our code style too, gnunet, 2017/02/24