mirror of
https://github.com/curl/curl.git
synced 2025-02-17 14:59:45 +08:00
tool_filetime: make -z work with file dates before 1970
Fixes #11785 Reported-by: Harry Sintonen Closes #11786
This commit is contained in:
parent
5949369c9f
commit
dffd996e3b
@ -32,9 +32,11 @@
|
||||
# include <sys/utime.h>
|
||||
#endif
|
||||
|
||||
curl_off_t getfiletime(const char *filename, struct GlobalConfig *global)
|
||||
/* Returns 0 on success, non-zero on file problems */
|
||||
int getfiletime(const char *filename, struct GlobalConfig *global,
|
||||
curl_off_t *stamp)
|
||||
{
|
||||
curl_off_t result = -1;
|
||||
int rc = 1;
|
||||
|
||||
/* Windows stat() may attempt to adjust the unix GMT file time by a daylight
|
||||
saving time offset and since it's GMT that is bad behavior. When we have
|
||||
@ -52,13 +54,13 @@ curl_off_t getfiletime(const char *filename, struct GlobalConfig *global)
|
||||
FILETIME ft;
|
||||
if(GetFileTime(hfile, NULL, NULL, &ft)) {
|
||||
curl_off_t converted = (curl_off_t)ft.dwLowDateTime
|
||||
| ((curl_off_t)ft.dwHighDateTime) << 32;
|
||||
| ((curl_off_t)ft.dwHighDateTime) << 32;
|
||||
|
||||
if(converted < CURL_OFF_T_C(116444736000000000)) {
|
||||
if(converted < CURL_OFF_T_C(116444736000000000))
|
||||
warnf(global, "Failed to get filetime: underflow");
|
||||
}
|
||||
else {
|
||||
result = (converted - CURL_OFF_T_C(116444736000000000)) / 10000000;
|
||||
*stamp = (converted - CURL_OFF_T_C(116444736000000000)) / 10000000;
|
||||
rc = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -76,13 +78,13 @@ curl_off_t getfiletime(const char *filename, struct GlobalConfig *global)
|
||||
#else
|
||||
struct_stat statbuf;
|
||||
if(-1 != stat(filename, &statbuf)) {
|
||||
result = (curl_off_t)statbuf.st_mtime;
|
||||
*stamp = (curl_off_t)statbuf.st_mtime;
|
||||
rc = 0;
|
||||
}
|
||||
else if(errno != ENOENT) {
|
||||
else
|
||||
warnf(global, "Failed to get filetime: %s", strerror(errno));
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
return rc;
|
||||
}
|
||||
|
||||
#if defined(HAVE_UTIME) || defined(HAVE_UTIMES) || defined(WIN32)
|
||||
|
@ -27,7 +27,8 @@
|
||||
|
||||
struct GlobalConfig;
|
||||
|
||||
curl_off_t getfiletime(const char *filename, struct GlobalConfig *global);
|
||||
int getfiletime(const char *filename, struct GlobalConfig *global,
|
||||
curl_off_t *stamp);
|
||||
|
||||
#if defined(HAVE_UTIME) || defined(HAVE_UTIMES) || \
|
||||
(defined(WIN32) && (SIZEOF_CURL_OFF_T >= 8))
|
||||
|
@ -2648,11 +2648,11 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
|
||||
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! */
|
||||
curl_off_t filetime = getfiletime(nextarg, global);
|
||||
if(filetime >= 0) {
|
||||
curl_off_t filetime;
|
||||
rc = getfiletime(nextarg, global, &filetime);
|
||||
if(!rc)
|
||||
/* pull the time out from the file */
|
||||
config->condtime = filetime;
|
||||
}
|
||||
else {
|
||||
/* failed, remove time condition */
|
||||
config->timecond = CURL_TIMECOND_NONE;
|
||||
|
Loading…
Reference in New Issue
Block a user