1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

[svn] When -E is in use, check for file existence after appending ".html" to the

name and modify the file name if necessary.
This commit is contained in:
hniksic 2005-06-17 15:06:26 -07:00
parent 25cbd9f692
commit 1805044ecd
2 changed files with 29 additions and 8 deletions

View File

@ -1,3 +1,9 @@
2005-06-18 Hrvoje Niksic <hniksic@xemacs.org>
* http.c (gethttp): When -E is in use, check for file existence
after appending ".html" to the name and modify the file name if
necessary.
2005-06-17 Hrvoje Niksic <hniksic@xemacs.org> 2005-06-17 Hrvoje Niksic <hniksic@xemacs.org>
* connect.c (socket_has_inet6): Removed. * connect.c (socket_has_inet6): Removed.

View File

@ -1121,6 +1121,12 @@ time_t http_atotm PARAMS ((const char *));
request_set_header (req, "User-Agent", opt.useragent, rel_none); \ request_set_header (req, "User-Agent", opt.useragent, rel_none); \
} while (0) } while (0)
/* The flags that allow clobbering the file (opening with "wb").
Defined here to avoid repetition later. #### This will require
rework. */
#define ALLOW_CLOBBER (opt.noclobber || opt.always_rest || opt.timestamping \
|| opt.dirstruct || opt.output_document)
/* Retrieve a document through HTTP protocol. It recognizes status /* Retrieve a document through HTTP protocol. It recognizes status
code, and correctly handles redirections. It closes the network code, and correctly handles redirections. It closes the network
socket. If it receives an error from the functions below it, it socket. If it receives an error from the functions below it, it
@ -1799,12 +1805,22 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy)
|| !(0 == strcasecmp (last_period_in_local_filename, ".htm") || !(0 == strcasecmp (last_period_in_local_filename, ".htm")
|| 0 == strcasecmp (last_period_in_local_filename, ".html"))) || 0 == strcasecmp (last_period_in_local_filename, ".html")))
{ {
size_t local_filename_len = strlen(*hs->local_file); int local_filename_len = strlen (*hs->local_file);
/* Resize the local file, allowing for ".html" preceded by
optional ".NUMBER". */
*hs->local_file = xrealloc (*hs->local_file, *hs->local_file = xrealloc (*hs->local_file,
local_filename_len + sizeof(".html")); local_filename_len + 24 + sizeof (".html"));
strcpy(*hs->local_file + local_filename_len, ".html"); strcpy(*hs->local_file + local_filename_len, ".html");
/* If clobbering is not allowed and the file, as named,
exists, tack on ".NUMBER.html" instead. */
if (!ALLOW_CLOBBER)
{
int ext_num = 1;
do
sprintf (*hs->local_file + local_filename_len,
".%d.html", ext_num++);
while (file_exists_p (*hs->local_file));
}
*dt |= ADDED_HTML_EXTENSION; *dt |= ADDED_HTML_EXTENSION;
} }
} }
@ -1897,8 +1913,7 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy)
rotate_backups (*hs->local_file); rotate_backups (*hs->local_file);
if (hs->restval) if (hs->restval)
fp = fopen (*hs->local_file, "ab"); fp = fopen (*hs->local_file, "ab");
else if (opt.noclobber || opt.always_rest || opt.timestamping || opt.dirstruct else if (ALLOW_CLOBBER)
|| opt.output_document)
fp = fopen (*hs->local_file, "wb"); fp = fopen (*hs->local_file, "wb");
else else
{ {