From efa6f012d88b303ba1cbd8f91e95b81320a09af5 Mon Sep 17 00:00:00 2001 From: green Date: Sat, 23 Oct 1999 15:22:53 +0000 Subject: [PATCH] Add the -F option. This is for forcing restarts with -r by inhibiting transmission of the If-Range HTTP header field. --- usr.bin/fetch/fetch.1 | 12 ++++++++++-- usr.bin/fetch/fetch.h | 1 + usr.bin/fetch/http.c | 8 +++++--- usr.bin/fetch/main.c | 8 ++++++-- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/usr.bin/fetch/fetch.1 b/usr.bin/fetch/fetch.1 index 40b6835eaa2e..919b5591b233 100644 --- a/usr.bin/fetch/fetch.1 +++ b/usr.bin/fetch/fetch.1 @@ -7,14 +7,14 @@ .Nd retrieve a file by Uniform Resource Locator .Sh SYNOPSIS .Nm fetch -.Op Fl AMPablmnpqrtv +.Op Fl AFMPablmnpqrtv .Op Fl S Ar size .Op Fl T Ar timeout .Op Fl o Ar file .Ar URL .Op Ar ... .Nm fetch -.Op Fl MPRlmnpqrv +.Op Fl FMPRlmnpqrv .Op Fl S Ar size .Op Fl o Ar file .Op Fl c Ar dir @@ -65,6 +65,14 @@ protocol. The file to retrieve is in directory .Ar dir on the remote host. +.It Fl F +Force restart without checking for the local file's date matching +that of the remote file. Use this with +.Fl r +to restart a transfer of a partial file where the modification +time on the local file has been changed and you are sure that the +remote file is still the same, as this will prevent retrieval from +starting anew. .It Fl f Ar file The file to retrieve is named .Ar file diff --git a/usr.bin/fetch/fetch.h b/usr.bin/fetch/fetch.h index bea7db93a38e..22e4294e3c2b 100644 --- a/usr.bin/fetch/fetch.h +++ b/usr.bin/fetch/fetch.h @@ -53,6 +53,7 @@ struct fetch_state { int fs_use_connect; /* -t option */ off_t fs_expectedsize; /* -S option */ int fs_reportsize; /* -s option */ + int fs_forcerestart; /* -F option */ time_t fs_modtime; void *fs_proto; int (*fs_retrieve)(struct fetch_state *); diff --git a/usr.bin/fetch/http.c b/usr.bin/fetch/http.c index 4e19485a9f8f..3025ecc72efe 100644 --- a/usr.bin/fetch/http.c +++ b/usr.bin/fetch/http.c @@ -564,9 +564,11 @@ http_retrieve(struct fetch_state *fs) if (((!to_stdout && stat(fs->fs_outputfile, &stab) == 0) || (to_stdout && fstat(STDOUT_FILENO, &stab) == 0)) && S_ISREG(stab.st_mode)) { - addstr(iov, n, "If-Range: "); - addstr(iov, n, format_http_date(stab.st_mtime)); - addstr(iov, n, "\r\n"); + if (!fs->fs_forcerestart) { + addstr(iov, n, "If-Range: "); + addstr(iov, n, format_http_date(stab.st_mtime)); + addstr(iov, n, "\r\n"); + } sprintf(rangebuf, "Range: bytes=%qd-\r\n", (long long)stab.st_size); addstr(iov, n, rangebuf); diff --git a/usr.bin/fetch/main.c b/usr.bin/fetch/main.c index 7cae99ba4e06..63c7aee8ba85 100644 --- a/usr.bin/fetch/main.c +++ b/usr.bin/fetch/main.c @@ -52,7 +52,7 @@ static void usage(void) { fprintf(stderr, - "usage: fetch [-ADHILMNPRTVablmnpqrstv] [-o outputfile] " + "usage: fetch [-ADHILMNPRTVablFmnpqrstv] [-o outputfile] " "[-S bytes]\n" " [-f file -h host [-c dir] | URL]\n"); exit(EX_USAGE); @@ -76,7 +76,7 @@ main(int argc, char *const *argv) fs.fs_expectedsize = -1; change_to_dir = file_to_get = hostname = 0; -#define OPT_STRING "Aabc:D:f:h:HIlLmMnNo:pPqRrS:stT:vV:" +#define OPT_STRING "Aabc:D:Ff:h:HIlLmMnNo:pPqRrS:stT:vV:" while ((c = getopt(argc, argv, OPT_STRING)) != -1) { switch (c) { case 'A': @@ -86,6 +86,10 @@ main(int argc, char *const *argv) case 'D': case 'H': case 'I': case 'L': case 'N': case 'V': break; /* ncftp compatibility */ + case 'F': + fs.fs_forcerestart = 1; + break; + case 'a': fs.fs_auto_retry = 1; break;