]> sjero.net Git - wget/commitdiff
Add --unlink.
authorMerinov Nikolay <kim.roader@gmail.com>
Wed, 29 Sep 2010 11:34:09 +0000 (13:34 +0200)
committerGiuseppe Scrivano <gscrivano@gnu.org>
Wed, 29 Sep 2010 11:34:09 +0000 (13:34 +0200)
doc/ChangeLog
doc/wget.texi
src/ChangeLog
src/exits.c
src/ftp.c
src/http.c
src/init.c
src/main.c
src/options.h
src/wget.h

index c404f75d22f1d714e1e1d4d372ad442885809575..c1bae6c1cb7d5ec06320db5fc7915aa2555456bc 100644 (file)
@@ -1,3 +1,7 @@
+2010-09-25  Merinov Nikolay  <kim.roader@gmail.com>
+
+       * wget.texi (Download Options): Document --unlink option.
+
 2010-09-13  Giuseppe Scrivano  <gscrivano@gnu.org>
 
        * wget.texi (Recursive Accept/Reject Options): Remove superfluous dot.
index 675a036a7bff403256b2056f2a1605387e3ee625..950c1eaac8a0266b9f379cc8fe5aa7ba61326520 100644 (file)
@@ -1075,6 +1075,13 @@ header and in HTML @code{Content-Type http-equiv} meta tag.
 You can set the default encoding using the @code{remoteencoding}
 command in @file{.wgetrc}. That setting may be overridden from the
 command line.
+
+@cindex unlink
+@item --unlink
+
+Force Wget to unlink file instead of clobbering existing file. This
+option is useful for downloading to the directory with hardlinks.
+
 @end table
 
 @node Directory Options, HTTP Options, Download Options, Invoking
index 0e244f8ffbf3af327ecca5964616f49900b679f7..624ae485bb8c28de45024bcbd31c0de77237e752 100644 (file)
@@ -1,3 +1,15 @@
+2010-09-25  Merinov Nikolay  <kim.roader@gmail.com>
+
+       * init.c: Add "unlink" command into command list.
+       * main.c: Add "unlink" option into option_data list.
+       * options.h: Adding unlink field into struct options.
+       * wget.h: Addind UNLINKERR error into uerr_t enum.
+       * exits.c (get_status_for_err): define status for UNLINKERR.
+       * ftp.c (getftp): unlink file if exists, instead clobbering.
+       (ftp_loop_internal): processing UNLINKERR.
+       * http.c (gethttp): unlink file if exists, instead clobbering.
+       (http_loop): processing UNLINKERR.
+
 2010-09-24  Dennis, CHENG Renquan <crquan@fedoraproject.org>
 
        Fix problem when content-disposition is used with recursive downloading.
index 273a67789c4aeac1e02a33daf025475b3cde3be9..23a66ac1fba86f696dffa0ae1a7ef09c83ca7c5f 100644 (file)
@@ -59,6 +59,7 @@ get_status_for_err (uerr_t err)
     case RETROK:
       return WGET_EXIT_SUCCESS;
     case FOPENERR: case FOPEN_EXCL_ERR: case FWRITEERR: case WRITEFAILED:
+    case UNLINKERR:
       return WGET_EXIT_IO_FAIL;
     case NOCONERROR: case HOSTERR: case CONSOCKERR: case CONERROR:
     case CONSSLERR: case CONIMPOSSIBLE: case FTPRERR: case FTPINVPASV:
index d3f6b18ba36eacd62e6c5fec908a74902f7da524..cba545002d9039a936bfd18da3dcb0852387374d 100644 (file)
--- a/src/ftp.c
+++ b/src/ftp.c
@@ -1173,7 +1173,22 @@ Error in server response, closing control connection.\n"));
         }
       else if (opt.noclobber || opt.always_rest || opt.timestamping || opt.dirstruct
                || opt.output_document)
-        {
+        {        
+         if (opt.unlink && file_exists_p (con->target))
+           {
+             int res = unlink (con->target);
+             if (res < 0)
+               {
+                 logprintf (LOG_NOTQUIET, "%s: %s\n", con->target,
+                            strerror (errno));
+                 fd_close (csock);
+                 con->csock = -1;
+                 fd_close (dtsock);
+                 fd_close (local_sock);
+                 return UNLINKERR;
+               }
+           }
+
 #ifdef __VMS
           int open_id;
 
@@ -1484,6 +1499,7 @@ ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con, char **local_fi
         {
         case HOSTERR: case CONIMPOSSIBLE: case FWRITEERR: case FOPENERR:
         case FTPNSFOD: case FTPLOGINC: case FTPNOPASV: case CONTNOTSUPPORTED:
+        case UNLINKERR:
           /* Fatal errors, give up.  */
           return err;
         case CONSOCKERR: case CONERROR: case FTPSRVERR: case FTPRERR:
index 0b1d644bb6e3803ef70086bbd77780855a53a715..6d9b1e9b70c88c65973153d93e07f2d401962abf 100644 (file)
@@ -2486,6 +2486,19 @@ File %s already there; not retrieving.\n\n"), quote (hs->local_file));
         }
       else if (ALLOW_CLOBBER)
         {
+         if (opt.unlink && file_exists_p (hs->local_file))
+           {
+             int res = unlink (hs->local_file);
+             if (res < 0)
+               {
+                 logprintf (LOG_NOTQUIET, "%s: %s\n", hs->local_file,
+                            strerror (errno));
+                 CLOSE_INVALIDATE (sock);
+                 xfree (head);
+                 return UNLINKERR;
+               }
+           }
+
 #ifdef __VMS
           int open_id;
 
@@ -2782,6 +2795,13 @@ Spider mode enabled. Check if remote file exists.\n"));
           logprintf (LOG_NOTQUIET, _("Unable to establish SSL connection.\n"));
           ret = err;
           goto exit;
+        case UNLINKERR:
+          /* Another fatal error.  */
+          logputs (LOG_VERBOSE, "\n");
+          logprintf (LOG_NOTQUIET, _("Cannot unlink %s (%s).\n"),
+                     quote (hstat.local_file), strerror (errno));
+          ret = err;
+          goto exit;
         case NEWLOCATION:
           /* Return the new location to the caller.  */
           if (!*newloc)
index 22394d11d1c16ab985354f917e6721d78926acd0..db67868cd9f4972a4b9d45c3107072a871460f3b 100644 (file)
@@ -253,6 +253,7 @@ static const struct {
   { "timestamping",     &opt.timestamping,      cmd_boolean },
   { "tries",            &opt.ntry,              cmd_number_inf },
   { "trustservernames", &opt.trustservernames,  cmd_boolean },
+  { "unlink",           &opt.unlink,            cmd_boolean },
   { "useproxy",         &opt.use_proxy,         cmd_boolean },
   { "user",             &opt.user,              cmd_string },
   { "useragent",        NULL,                   cmd_spec_useragent },
index 53e27ce9bdb4b4ccbfd639bf6021bbe562d0ef97..03c6b86219a677650874de64afe91f90b28b397d 100644 (file)
@@ -266,6 +266,7 @@ static struct cmdline_option option_data[] =
     { "timeout", 'T', OPT_VALUE, "timeout", -1 },
     { "timestamping", 'N', OPT_BOOLEAN, "timestamping", -1 },
     { "tries", 't', OPT_VALUE, "tries", -1 },
+    { "unlink", 0, OPT_BOOLEAN, "unlink", -1 },
     { "trust-server-names", 0, OPT_BOOLEAN, "trustservernames", -1 },
     { "use-server-timestamps", 0, OPT_BOOLEAN, "useservertimestamps", -1 },
     { "user", 0, OPT_VALUE, "user", -1 },
@@ -515,6 +516,8 @@ Download:\n"),
        --local-encoding=ENC      use ENC as the local encoding for IRIs.\n"),
     N_("\
        --remote-encoding=ENC     use ENC as the default remote encoding.\n"),
+    N_("\
+       --unlink                  remove file before clobber.\n"),
     "\n",
 
     N_("\
index 9fbedb785f3fff7a6108b0fd8393aa8225c31735..e9fe2d2c0b6f7679e80629d71cb19f1bc62e882a 100644 (file)
@@ -54,6 +54,7 @@ struct options
   bool protocol_directories;   /* Whether to prepend "http"/"ftp" to dirs. */
   bool noclobber;              /* Disables clobbering of existing
                                   data. */
+  bool unlink;                 /* remove file before clobbering */
   char *dir_prefix;            /* The top of directory tree */
   char *lfilename;             /* Log filename */
   char *input_filename;                /* Input filename */
index bbefae053612011561e7fee17698b789f1a5d75e..c267cbf860ac98325f153e82186ac37a988b2869 100644 (file)
@@ -351,7 +351,8 @@ typedef enum
   RETRBADPATTERN, RETNOTSUP /* ! */, ROBOTSOK /* ! */, NOROBOTS /* ! */,
   PROXERR,
   /* 50  */
-  AUTHFAILED, QUOTEXC, WRITEFAILED, SSLINITFAILED, VERIFCERTERR
+  AUTHFAILED, QUOTEXC, WRITEFAILED, SSLINITFAILED, VERIFCERTERR,
+  UNLINKERR
 } uerr_t;
 
 /* 2005-02-19 SMS.