diff options
author | joerg <joerg> | 2009-02-05 17:14:06 +0000 |
---|---|---|
committer | joerg <joerg> | 2009-02-05 17:14:06 +0000 |
commit | 456f3adff8b0bfcb554fce9f3725b3846fc69fe8 (patch) | |
tree | 6e8d9be7b4a364805bf4003ee454b805ecc66894 /net/fetch/files | |
parent | 37c2dfa1930c0cc8e5b72d143ff1d92fcf5c7a06 (diff) | |
download | pkgsrc-456f3adff8b0bfcb554fce9f3725b3846fc69fe8.tar.gz |
fetch-1.2:
Add -i option for conditional fetch, e.g. only fetch the file again, if
the remote version is newer.
Diffstat (limited to 'net/fetch/files')
-rw-r--r-- | net/fetch/files/fetch.1 | 6 | ||||
-rw-r--r-- | net/fetch/files/fetch.c | 29 | ||||
-rw-r--r-- | net/fetch/files/fetch.cat1 | 7 |
3 files changed, 37 insertions, 5 deletions
diff --git a/net/fetch/files/fetch.1 b/net/fetch/files/fetch.1 index eaf6a297015..0d75628be28 100644 --- a/net/fetch/files/fetch.1 +++ b/net/fetch/files/fetch.1 @@ -37,7 +37,7 @@ .Nd retrieve a file by Uniform Resource Locator .Sh SYNOPSIS .Nm -.Op Fl 146AFMRUadlmnqrsv +.Op Fl 146AFMRUadilmnqrsv .Op Fl B Ar bytes .Op Fl S Ar bytes .Op Fl T Ar seconds @@ -110,6 +110,10 @@ The file to retrieve is located on the host .Ar host . This option is deprecated and is provided for backward compatibility only. +.It Fl i +Only fetch if it the output file is older than the referenced URL. +This option is overriden by +.Fl o Ar - . .It Fl l If the target is a file-scheme URL, make a symbolic link to the target rather than trying to copy it. diff --git a/net/fetch/files/fetch.c b/net/fetch/files/fetch.c index 1eb8f7e3e72..9cdb19c26b8 100644 --- a/net/fetch/files/fetch.c +++ b/net/fetch/files/fetch.c @@ -90,6 +90,7 @@ int d_flag; /* -d: direct connection */ 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: fetch file if modified */ int l_flag; /* -l: link rather than copy file: URLs */ int m_flag; /* -[Mm]: mirror mode */ char *N_filename; /* -N: netrc file name */ @@ -393,6 +394,17 @@ fetch(char *URL, const char *path) break; } + /* Protocol independent flags */ + if (i_flag) { + if (stat(path, &sb) == 0) { + url->last_modified = sb.st_mtime; + strcat(flags, "i"); + } else if (errno != ENOENT) { + warn("%s: stat()", path); + goto failure; + } + } + /* FTP specific flags */ if (strcmp(url->scheme, SCHEME_FTP) == 0) { if (d_flag) @@ -474,6 +486,12 @@ fetch(char *URL, const char *path) alarm(0); if (sigalrm || sigint) goto signal; + if (f == NULL && i_flag && fetchLastErrCode == FETCH_UNCHANGED) { + /* URL was not modified, return OK. */ + printf("%s: not modified\n", URL); + r = 0; + goto done; + } if (f == NULL) { warnx("%s: %s", URL, fetchLastErrString); goto failure; @@ -747,7 +765,7 @@ static void usage(void) { fprintf(stderr, "%s\n%s\n%s\n", - "usage: fetch [-146AFMPRUadlmnpqrsv] [-N netrc] [-o outputfile]", + "usage: fetch [-146AFMPRUadilmnpqrsv] [-N netrc] [-o outputfile]", " [-S bytes] [-B bytes] [-T seconds] [-w seconds]", " [-h host -f file [-c dir] | URL ...]"); } @@ -766,7 +784,7 @@ main(int argc, char *argv[]) int c, e, r; while ((c = getopt(argc, argv, - "146AaB:bc:dFf:Hh:lMmN:no:qRrS:sT:tUvw:")) != -1) + "146AaB:bc:dFf:Hh:ilMmN:no:qRrS:sT:tUvw:")) != -1) switch (c) { case '1': once_flag = 1; @@ -811,6 +829,9 @@ main(int argc, char *argv[]) case 'h': h_hostname = optarg; break; + case 'i': + i_flag = 1; + break; case 'l': l_flag = 1; break; @@ -934,6 +955,10 @@ main(int argc, char *argv[]) if (o_flag) { if (strcmp(o_filename, "-") == 0) { o_stdout = 1; + if (i_flag) { + warnx("-i and -o - are incompatible, dropping -i"); + i_flag = 0; + } } else if (stat(o_filename, &sb) == -1) { if (errno == ENOENT) { if (argc > 1) diff --git a/net/fetch/files/fetch.cat1 b/net/fetch/files/fetch.cat1 index 3aaa043269a..6b73d66f5c4 100644 --- a/net/fetch/files/fetch.cat1 +++ b/net/fetch/files/fetch.cat1 @@ -4,7 +4,7 @@ NNAAMMEE ffeettcchh -- retrieve a file by Uniform Resource Locator SSYYNNOOPPSSIISS - ffeettcchh [--114466AAFFMMRRUUaaddllmmnnqqrrssvv] [--BB _b_y_t_e_s] [--SS _b_y_t_e_s] [--TT _s_e_c_o_n_d_s] [--NN _f_i_l_e] + ffeettcchh [--114466AAFFMMRRUUaaddiillmmnnqqrrssvv] [--BB _b_y_t_e_s] [--SS _b_y_t_e_s] [--TT _s_e_c_o_n_d_s] [--NN _f_i_l_e] [--oo _f_i_l_e] [--ww _s_e_c_o_n_d_s] [--hh _h_o_s_t] [--cc _d_i_r] [--ff _f_i_l_e] [_U_R_L _._._.] DDEESSCCRRIIPPTTIIOONN @@ -50,6 +50,9 @@ DDEESSCCRRIIPPTTIIOONN option is deprecated and is provided for backward compatibil- ity only. + --ii Only fetch if it the output file is older than the referenced + URL. This option is overriden by --oo _-. + --ll If the target is a file-scheme URL, make a symbolic link to the target rather than trying to copy it. @@ -150,4 +153,4 @@ NNOOTTEESS One cannot both use the --hh, --cc and --ff options and specify URLs on the command line. -NetBSD 4.0 March 11, 2003 NetBSD 4.0 +NetBSD 5.0 March 11, 2003 NetBSD 5.0 |