]> sjero.net Git - wget/blobdiff - src/http.c
Add --unlink.
[wget] / src / http.c
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)