pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/net/fetch fetch-1.2:



details:   https://anonhg.NetBSD.org/pkgsrc/rev/65ec23fb56a8
branches:  trunk
changeset: 553984:65ec23fb56a8
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Thu Feb 05 17:14:06 2009 +0000

description:
fetch-1.2:
Add -i option for conditional fetch, e.g. only fetch the file again, if
the remote version is newer.

diffstat:

 net/fetch/Makefile         |   4 ++--
 net/fetch/files/fetch.1    |   6 +++++-
 net/fetch/files/fetch.c    |  29 +++++++++++++++++++++++++++--
 net/fetch/files/fetch.cat1 |   7 +++++--
 4 files changed, 39 insertions(+), 7 deletions(-)

diffs (145 lines):

diff -r 39cb646d3998 -r 65ec23fb56a8 net/fetch/Makefile
--- a/net/fetch/Makefile        Thu Feb 05 16:59:45 2009 +0000
+++ b/net/fetch/Makefile        Thu Feb 05 17:14:06 2009 +0000
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.2 2009/02/04 21:29:40 joerg Exp $
+# $NetBSD: Makefile,v 1.3 2009/02/05 17:14:06 joerg Exp $
 #
 
-DISTNAME=      fetch-1.1
+DISTNAME=      fetch-1.2
 CATEGORIES=    net
 MASTER_SITES=  # empty
 DISTFILES=     # empty
diff -r 39cb646d3998 -r 65ec23fb56a8 net/fetch/files/fetch.1
--- a/net/fetch/files/fetch.1   Thu Feb 05 16:59:45 2009 +0000
+++ b/net/fetch/files/fetch.1   Thu Feb 05 17:14:06 2009 +0000
@@ -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 @@
 .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 -r 39cb646d3998 -r 65ec23fb56a8 net/fetch/files/fetch.c
--- a/net/fetch/files/fetch.c   Thu Feb 05 16:59:45 2009 +0000
+++ b/net/fetch/files/fetch.c   Thu Feb 05 17:14:06 2009 +0000
@@ -90,6 +90,7 @@
 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 @@
                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 @@
                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 @@
 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 @@
        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 @@
                case 'h':
                        h_hostname = optarg;
                        break;
+               case 'i':
+                       i_flag = 1;
+                       break;
                case 'l':
                        l_flag = 1;
                        break;
@@ -934,6 +955,10 @@
        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 -r 39cb646d3998 -r 65ec23fb56a8 net/fetch/files/fetch.cat1
--- a/net/fetch/files/fetch.cat1        Thu Feb 05 16:59:45 2009 +0000
+++ b/net/fetch/files/fetch.cat1        Thu Feb 05 17:14:06 2009 +0000
@@ -4,7 +4,7 @@
      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 @@
                  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 @@
      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



Home | Main Index | Thread Index | Old Index