[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnurl] 160/205: tool_operate: move filetime code to its ow
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnurl] 160/205: tool_operate: move filetime code to its own function |
Date: |
Thu, 20 Apr 2017 16:21:40 +0200 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to annotated tag gnurl-7.54.0
in repository gnurl.
commit 446eaa941d29dd728a81847b5ca2424b0f254cf5
Author: Marcel Raad <address@hidden>
AuthorDate: Sat Apr 1 11:22:53 2017 +0200
tool_operate: move filetime code to its own function
Ref: https://github.com/curl/curl/pull/1378
---
src/tool_operate.c | 109 +++++++++++++++++++++++++++++------------------------
1 file changed, 60 insertions(+), 49 deletions(-)
diff --git a/src/tool_operate.c b/src/tool_operate.c
index 572c8d0cc..bb698ffec 100644
--- a/src/tool_operate.c
+++ b/src/tool_operate.c
@@ -184,6 +184,64 @@ static curl_off_t VmsSpecialSize(const char *name,
}
#endif /* __VMS */
+#if defined(HAVE_UTIME) || \
+ (defined(WIN32) && (CURL_SIZEOF_CURL_OFF_T >= 8))
+static void setfiletime(long filetime, const char *filename,
+ FILE *error_stream)
+{
+ 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(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(error_stream,
+ "Failed to set filetime %ld on outfile: "
+ "SetFileTime failed: GetLastError %u\n",
+ filetime, GetLastError());
+ }
+ CloseHandle(hfile);
+ }
+ else {
+ fprintf(error_stream,
+ "Failed to set filetime %ld on outfile: "
+ "CreateFile failed: GetLastError %u\n",
+ filetime, GetLastError());
+ }
+ }
+ else {
+ fprintf(error_stream,
+ "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;
+ if(utime(filename, ×)) {
+ fprintf(error_stream,
+ "Failed to set filetime %ld on outfile: errno %d\n",
+ filetime, errno);
+ }
+#endif
+ }
+}
+#endif /* defined(HAVE_UTIME) || \
+ (defined(WIN32) && (CURL_SIZEOF_CURL_OFF_T >= 8)) */
+
static CURLcode operate_do(struct GlobalConfig *global,
struct OperationConfig *config)
{
@@ -1761,55 +1819,8 @@ static CURLcode operate_do(struct GlobalConfig *global,
/* 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;
- if(utime(outs.filename, ×)) {
- fprintf(config->global->errors,
- "Failed to set filetime %ld on outfile: errno %d\n",
- filetime, errno);
- }
-#endif
- }
+ if(filetime >= 0)
+ setfiletime(filetime, outs.filename, config->global->errors);
}
#endif /* defined(HAVE_UTIME) || \
(defined(WIN32) && (CURL_SIZEOF_CURL_OFF_T >= 8)) */
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnurl] 203/205: RELEASE-NOTES: curl 7.54.0, (continued)
- [GNUnet-SVN] [gnurl] 203/205: RELEASE-NOTES: curl 7.54.0, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 112/205: spelling fixes, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 93/205: RELEASE-NOTES: synced with 6e0f26c8a8c28df, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 111/205: curl: check for end of input in writeout backslash handling, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 163/205: test1541: ignore the curl_off_t variable type name comparison, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 107/205: openssl: made the error table static const, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 151/205: llist: replace Curl_llist_alloc with Curl_llist_init, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 164/205: INSTALL.cmake: more problems, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 133/205: gcc7: fix ‘*’ in boolean context, suggest ‘&&’ instead [-Wint-in-bool-context], gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 148/205: include: curl/system.h is a run-time version of curlbuild.h, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 160/205: tool_operate: move filetime code to its own function,
gnunet <=
- [GNUnet-SVN] [gnurl] 170/205: sspi: print out InitializeSecurityContext() error message, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 180/205: RELEASE-NOTES: synced with f9d1e9a27f7e1, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 162/205: Revert "configure: prefer 'long long' to int64_t for curl_off_t", gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 166/205: system.h: set sizeof long to 4 on "default 32 bit" systems, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 195/205: configure.ac: ignore CR after version numbers, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 176/205: CURLINFO_SCHEME.3: fix variable type, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 193/205: unit1303: fix compiler warning, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 201/205: TLS: Fix switching off SSL session id when client cert is used, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 154/205: url: don't free postponed data on connection reuse, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 69/205: http_proxy: Ignore TE and CL in CONNECT 2xx responses, gnunet, 2017/04/20