d5d7871c9ce692f443b5a1f64194b4abe889f6b8 galt Mon Mar 7 22:21:10 2011 -0800 fixing processing of last-modified header in udc; also setting the original time on the finished file in paraFetch (net.c); new helper function in common.c handles conversion to UTC time diff --git src/lib/net.c src/lib/net.c index 284f05e..01c1926 100644 --- src/lib/net.c +++ src/lib/net.c @@ -5,30 +5,31 @@ #include "common.h" #include <signal.h> #include <errno.h> #include <string.h> #include <sys/time.h> #include "internet.h" #include "errabort.h" #include "hash.h" #include "net.h" #include "linefile.h" #include "base64.h" #include "cheapcgi.h" #include "https.h" #include "sqlNum.h" +#include <utime.h> static char const rcsid[] = "$Id: net.c,v 1.80 2010/04/14 07:42:06 galt Exp $"; /* Brought errno in to get more useful error messages */ extern int errno; static int netStreamSocket() /* Create a TCP/IP streaming socket. Complain and return something * negative if can't */ { int sd = socket(AF_INET, SOCK_STREAM, 0); if (sd < 0) warn("Couldn't make AF_INET socket."); return sd; @@ -1845,30 +1846,67 @@ } connOpen = 0; reOpen = 0; /* sleep for a while, maybe the server will recover */ sleep(RETRYSLEEPTIME); } } } close(out); /* delete the status file - by passing TRUE */ writeParaFetchStatus(origPath, pcList, url, fileSize, dateString, TRUE); // DEBUG RESTORE!! +/* restore original file datestamp mtime from last-modified header */ +struct tm tm; +// Last-Modified: Wed, 15 Nov 1995 04:58:08 GMT +// These strings are always GMT +if (strptime(dateString, "%a, %d %b %Y %H:%M:%S %Z", &tm) == NULL) + { + warn("unable to parse last-modified string [%s]", dateString); + } +else + { + time_t t; + // convert to UTC (GMT) time + t = mktimeFromUtc(&tm); + if (t == -1) + { + warn("mktimeFromUtc failed while converting last-modified string to UTC [%s]", dateString); + } + else + { + // update the file mtime + struct utimbuf ut; + struct stat mystat; + ZeroVar(&mystat); + if (stat(outTemp,&mystat)==0) + { + ut.actime = mystat.st_atime; + ut.modtime = t; + if (utime(outTemp, &ut)==-1) + { + char errMsg[256]; + safef(errMsg, sizeof(errMsg), "paraFetch: error setting modification time of %s to %s\n", outTemp, dateString); + perror(errMsg); + } + } + } + } + /* rename the successful download to the original name */ rename(outTemp, origPath); if (fileSize != -1 && totalDownloaded != fileSize) { warn("Unexpected result: Total downloaded bytes %lld is not equal to fileSize %lld" , (long long) totalDownloaded , (long long) fileSize); return FALSE; } return TRUE; } struct lineFile *netLineFileOpen(char *url)