[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-wget] bug #24806, Option to unlink before clobber
From: |
Giuseppe Scrivano |
Subject: |
Re: [Bug-wget] bug #24806, Option to unlink before clobber |
Date: |
Wed, 28 Jul 2010 14:49:06 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
it seems good. I will send you in another email details to get
copyright assignments papers to the FSF.
Cheers,
Giuseppe
Merinov Nikolay <address@hidden> writes:
> I writting patch, that add "--unlink" options for unlink file instead
> clobbering.
>
> I also posted this patch in discussion on
> http://savannah.gnu.org/bugs/?24806
>
> This would be my first contribution to wget. Criticism/feedback
> encouraged.
>
>
> ChangeLog
>
> 2010-07-25 Merinov Nikolay <address@hidden>
>
> * init.c: Adding "unlink" command into command list
> * main.c: Adding "unlink" option into option_data list
> * options.h: Adding unlink field into struct options
> * wget.h: Addind FUNLINKERR error into uerr_t enum
> * exits.c (get_status_for_err): define status for FUNLINKERR
> * ftp.c (getftp): unlink file if exists, instead clobbering
> (ftp_loop_internal): processing FUNLINKERR
> * http.c (gethttp): unlink file if exists, instead clobbering
> (http_loop): processing FUNLINKERR
>
> Patch
>
> === modified file 'src/exits.c'
> --- src/exits.c 2010-05-08 19:56:15 +0000
> +++ src/exits.c 2010-07-25 17:30:19 +0000
> @@ -59,6 +59,7 @@
> case RETROK:
> return WGET_EXIT_SUCCESS;
> case FOPENERR: case FOPEN_EXCL_ERR: case FWRITEERR: case WRITEFAILED:
> + case FUNLINKERR:
> return WGET_EXIT_IO_FAIL;
> case NOCONERROR: case HOSTERR: case CONSOCKERR: case CONERROR:
> case CONSSLERR: case CONIMPOSSIBLE: case FTPRERR: case FTPINVPASV:
>
> === modified file 'src/ftp.c'
> --- src/ftp.c 2010-07-20 11:09:43 +0000
> +++ src/ftp.c 2010-07-25 17:32:35 +0000
> @@ -1173,7 +1173,22 @@
> }
> else if (opt.noclobber || opt.always_rest || opt.timestamping ||
> opt.dirstruct
> || opt.output_document)
> - {
> + {
> + if (opt.unlink && file_exists_p (con->target))
> + {
> + int res = remove (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 FUNLINKERR;
> + }
> + }
> +
> #ifdef __VMS
> int open_id;
>
> @@ -1484,6 +1499,7 @@
> {
> case HOSTERR: case CONIMPOSSIBLE: case FWRITEERR: case FOPENERR:
> case FTPNSFOD: case FTPLOGINC: case FTPNOPASV: case CONTNOTSUPPORTED:
> + case FUNLINKERR:
> /* Fatal errors, give up. */
> return err;
> case CONSOCKERR: case CONERROR: case FTPSRVERR: case FTPRERR:
>
> === modified file 'src/http.c'
> --- src/http.c 2010-07-20 17:42:13 +0000
> +++ src/http.c 2010-07-25 17:27:43 +0000
> @@ -2501,6 +2501,19 @@
> }
> else if (ALLOW_CLOBBER)
> {
> + if (opt.unlink && file_exists_p (hs->local_file))
> + {
> + int res = remove (hs->local_file);
> + if (res < 0)
> + {
> + logprintf (LOG_NOTQUIET, "%s: %s\n", hs->local_file,
> + strerror (errno));
> + CLOSE_INVALIDATE (sock);
> + xfree (head);
> + return FUNLINKERR;
> + }
> + }
> +
> #ifdef __VMS
> int open_id;
>
> @@ -2795,6 +2808,13 @@
> logprintf (LOG_NOTQUIET, _("Unable to establish SSL
> connection.\n"));
> ret = err;
> goto exit;
> + case FUNLINKERR:
> + /* 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)
>
> === modified file 'src/init.c'
> --- src/init.c 2010-05-08 19:56:15 +0000
> +++ src/init.c 2010-07-25 13:02:23 +0000
> @@ -252,6 +252,7 @@
> { "timeout", NULL, cmd_spec_timeout },
> { "timestamping", &opt.timestamping, cmd_boolean },
> { "tries", &opt.ntry, cmd_number_inf },
> + { "unlink", &opt.unlink, cmd_boolean },
> { "useproxy", &opt.use_proxy, cmd_boolean },
> { "user", &opt.user, cmd_string },
> { "useragent", NULL, cmd_spec_useragent },
>
> === modified file 'src/main.c'
> --- src/main.c 2010-06-20 10:10:35 +0000
> +++ src/main.c 2010-07-25 13:01:15 +0000
> @@ -266,6 +266,7 @@
> { "timeout", 'T', OPT_VALUE, "timeout", -1 },
> { "timestamping", 'N', OPT_BOOLEAN, "timestamping", -1 },
> { "tries", 't', OPT_VALUE, "tries", -1 },
> + { "unlink", 0, OPT_BOOLEAN, "unlink", -1 },
> { "use-server-timestamps", 0, OPT_BOOLEAN, "useservertimestamps", -1 },
> { "user", 0, OPT_VALUE, "user", -1 },
> { "user-agent", 'U', OPT_VALUE, "useragent", -1 },
> @@ -514,6 +515,8 @@
> --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_("\
>
> === modified file 'src/options.h'
> --- src/options.h 2010-05-08 19:56:15 +0000
> +++ src/options.h 2010-07-25 13:18:57 +0000
> @@ -54,6 +54,7 @@
> 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 */
>
> === modified file 'src/wget.h'
> --- src/wget.h 2010-05-08 19:56:15 +0000
> +++ src/wget.h 2010-07-25 17:19:21 +0000
> @@ -351,7 +351,8 @@
> RETRBADPATTERN, RETNOTSUP /* ! */, ROBOTSOK /* ! */, NOROBOTS /* ! */,
> PROXERR,
> /* 50 */
> - AUTHFAILED, QUOTEXC, WRITEFAILED, SSLINITFAILED, VERIFCERTERR
> + AUTHFAILED, QUOTEXC, WRITEFAILED, SSLINITFAILED, VERIFCERTERR,
> + FUNLINKERR
> } uerr_t;
>
> /* 2005-02-19 SMS.
>