time-cond: fix reading the file modification time on Windows

On Windows, stat() may adjust the unix file time by a daylight saving time
offset. Avoid this by calling GetFileTime() instead.

Fixes #2164
Closes #2204
This commit is contained in:
Michael Kaufmann 2018-02-05 21:57:39 +01:00
parent 84ad1fd304
commit d25b050379
6 changed files with 210 additions and 98 deletions

View file

@ -31,6 +31,7 @@
#include "tool_cfgable.h"
#include "tool_cb_prg.h"
#include "tool_convert.h"
#include "tool_filetime.h"
#include "tool_formparse.h"
#include "tool_getparam.h"
#include "tool_helpers.h"
@ -2087,11 +2088,15 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
break;
}
now = time(NULL);
config->condtime = curl_getdate(nextarg, &now);
if(-1 == (int)config->condtime) {
config->condtime = (curl_off_t)curl_getdate(nextarg, &now);
if(-1 == config->condtime) {
/* now let's see if it is a file name to get the time from instead! */
struct_stat statbuf;
if(-1 == stat(nextarg, &statbuf)) {
curl_off_t filetime = getfiletime(nextarg, config->global->errors);
if(filetime >= 0) {
/* pull the time out from the file */
config->condtime = filetime;
}
else {
/* failed, remove time condition */
config->timecond = CURL_TIMECOND_NONE;
warnf(global,
@ -2099,10 +2104,6 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
"a file name). Disabling time condition. "
"See curl_getdate(3) for valid date syntax.\n");
}
else {
/* pull the time out from the file */
config->condtime = statbuf.st_mtime;
}
}
break;
default: /* unknown flag */