? usr.bin/fetch/stokely.css Index: lib/libfetch/fetch.3 =================================================================== RCS file: /home/ncvs/src/lib/libfetch/fetch.3,v retrieving revision 1.60.2.3 diff -u -r1.60.2.3 fetch.3 --- lib/libfetch/fetch.3 24 Jan 2008 08:17:17 -0000 1.60.2.3 +++ lib/libfetch/fetch.3 10 Dec 2008 06:37:53 -0000 @@ -165,6 +165,7 @@ char *doc; off_t offset; size_t length; + time_t mtime; }; .Ed .Pp Index: lib/libfetch/fetch.h =================================================================== RCS file: /home/ncvs/src/lib/libfetch/fetch.h,v retrieving revision 1.26 diff -u -r1.26 fetch.h --- lib/libfetch/fetch.h 21 Sep 2004 18:35:20 -0000 1.26 +++ lib/libfetch/fetch.h 10 Dec 2008 06:37:53 -0000 @@ -46,6 +46,7 @@ char *doc; off_t offset; size_t length; + time_t mtime; }; struct url_stat { Index: lib/libfetch/http.c =================================================================== RCS file: /home/ncvs/src/lib/libfetch/http.c,v retrieving revision 1.76.2.3 diff -u -r1.76.2.3 http.c --- lib/libfetch/http.c 24 Jan 2008 08:17:17 -0000 1.76.2.3 +++ lib/libfetch/http.c 10 Dec 2008 06:37:53 -0000 @@ -63,6 +63,7 @@ #include #include +#include #include #include @@ -798,7 +799,7 @@ { conn_t *conn; struct url *url, *new; - int chunked, direct, need_auth, noredirect, verbose; + int chunked, direct, need_auth, noredirect, verbose, conditional; int e, i, n, val; off_t offset, clength, length, size; time_t mtime; @@ -806,11 +807,14 @@ FILE *f; hdr_t h; char hbuf[MAXHOSTNAMELEN + 7], *host; + struct tm *timestruct; + char timebuf[80]; direct = CHECK_FLAG('d'); noredirect = CHECK_FLAG('A'); verbose = CHECK_FLAG('v'); - + conditional = CHECK_FLAG('i'); + if (direct && purl) { fetchFreeURL(purl); purl = NULL; @@ -870,6 +874,7 @@ if (verbose) fetch_info("requesting %s://%s%s", url->scheme, host, url->doc); + if (purl) { http_cmd(conn, "%s %s://%s%s HTTP/1.1", op, url->scheme, host, url->doc); @@ -878,6 +883,18 @@ op, url->doc); } + if (conditional && url->mtime) { + timestruct = gmtime((time_t *)&url->mtime); + int r; + r = strftime((char *)&timebuf, 80, + "%a, %d %b %Y %T GMT", timestruct); + http_cmd(conn, "If-Modified-Since: %s", timebuf); + if (verbose) { + fetch_info("Conditional request: %s", + timebuf); + } + } + /* virtual host */ http_cmd(conn, "Host: %s", host); Index: usr.bin/fetch/fetch.1 =================================================================== RCS file: /home/ncvs/src/usr.bin/fetch/fetch.1,v retrieving revision 1.66.2.2 diff -u -r1.66.2.2 fetch.1 --- usr.bin/fetch/fetch.1 24 Jan 2008 08:17:50 -0000 1.66.2.2 +++ usr.bin/fetch/fetch.1 10 Dec 2008 06:37:53 -0000 @@ -43,6 +43,7 @@ .Op Fl T Ar seconds .Op Fl N Ar file .Op Fl o Ar file +.Op Fl i Ar file .Op Fl w Ar seconds .Op Fl h Ar host .Op Fl c Ar dir @@ -110,6 +111,10 @@ .Ar host . This option is deprecated and is provided for backward compatibility only. +.It Fl i Ar file +The file should only be retrieved if it is newer than +.Ar file +on the local host. .It Fl l If the target is a file-scheme URL, make a symbolic link to the target rather than trying to copy it. Index: usr.bin/fetch/fetch.c =================================================================== RCS file: /home/ncvs/src/usr.bin/fetch/fetch.c,v retrieving revision 1.75.2.3 diff -u -r1.75.2.3 fetch.c --- usr.bin/fetch/fetch.c 1 Sep 2008 23:55:38 -0000 1.75.2.3 +++ usr.bin/fetch/fetch.c 10 Dec 2008 06:37:53 -0000 @@ -60,6 +60,8 @@ int F_flag; /* -F: restart without checking mtime */ char *f_filename; /* -f: file to fetch */ char *h_hostname; /* -h: host to fetch from */ +int i_flag; /* -i: specify input file for mtime comparison */ +char *i_filename; /* name of input file */ int l_flag; /* -l: link rather than copy file: URLs */ int m_flag; /* -[Mm]: mirror mode */ char *N_filename; /* -N: netrc file name */ @@ -317,7 +319,7 @@ FILE *f, *of; size_t size, wr; off_t count; - char flags[8]; + char flags[9]; const char *slash; char *tmppath; int r; @@ -381,6 +383,15 @@ if (A_flag) strcat(flags, "A"); timeout = T_secs ? T_secs : http_timeout; + if (i_flag) { + r = stat(i_filename, &sb); + if (r == -1) { + warnx("Could not stat: %s", i_filename); + goto failure; + } + url->mtime = sb.st_mtime; + strcat(flags, "i"); + } } /* set the protocol timeout. */ @@ -730,7 +741,7 @@ int c, e, r; while ((c = getopt(argc, argv, - "146AaB:bc:dFf:Hh:lMmN:nPpo:qRrS:sT:tUvw:")) != -1) + "146AaB:bc:dFf:Hh:i:lMmN:nPpo:qRrS:sT:tUvw:")) != -1) switch (c) { case '1': once_flag = 1; @@ -775,6 +786,10 @@ case 'h': h_hostname = optarg; break; + case 'i': + i_flag = 1; + i_filename = optarg; + break; case 'l': l_flag = 1; break;