mirror of
https://github.com/mirror/wget.git
synced 2024-12-28 05:40:08 +08:00
Append .tmp to temporary files
* src/http.c (struct http_stat): Add `temporary` flag. (check_file_output): Append .tmp to temporary files. (open_output_stream): Refactor condition to use hs->temporary instead. Reported-by: "Misra, Deapesh" <dmisra@verisign.com> Discovered by: Dawid Golunski (http://legalhackers.com)
This commit is contained in:
parent
9ffb64ba6a
commit
690c47e3b1
6
NEWS
6
NEWS
@ -7,6 +7,12 @@ See the end for copying conditions.
|
||||
|
||||
Please send GNU Wget bug reports to <bug-wget@gnu.org>.
|
||||
|
||||
* Changes in Wget X.Y.Z
|
||||
|
||||
* On a recursive download, append a .tmp suffix to temporary files
|
||||
that will be deleted after being parsed, and create them
|
||||
readable/writable only by the owner.
|
||||
|
||||
* Changes in Wget 1.18
|
||||
|
||||
* By default, on server redirects to a FTP resource, use the original
|
||||
|
14
src/http.c
14
src/http.c
@ -1569,6 +1569,7 @@ struct http_stat
|
||||
#ifdef HAVE_METALINK
|
||||
metalink_t *metalink;
|
||||
#endif
|
||||
bool temporary; /* downloading a temporary file */
|
||||
};
|
||||
|
||||
static void
|
||||
@ -2259,6 +2260,15 @@ check_file_output (struct url *u, struct http_stat *hs,
|
||||
xfree (local_file);
|
||||
}
|
||||
|
||||
hs->temporary = opt.delete_after || opt.spider || !acceptable (hs->local_file);
|
||||
if (hs->temporary)
|
||||
{
|
||||
char *tmp = NULL;
|
||||
asprintf (&tmp, "%s.tmp", hs->local_file);
|
||||
xfree (hs->local_file);
|
||||
hs->local_file = tmp;
|
||||
}
|
||||
|
||||
/* TODO: perform this check only once. */
|
||||
if (!hs->existence_checked && file_exists_p (hs->local_file))
|
||||
{
|
||||
@ -2472,9 +2482,7 @@ open_output_stream (struct http_stat *hs, int count, FILE **fp)
|
||||
open_id = 22;
|
||||
*fp = fopen (hs->local_file, "wb", FOPEN_OPT_ARGS);
|
||||
#else /* def __VMS */
|
||||
if (opt.delete_after
|
||||
|| opt.spider /* opt.recursive is implicitely true */
|
||||
|| !acceptable (hs->local_file))
|
||||
if (hs->temporary)
|
||||
{
|
||||
*fp = fdopen (open (hs->local_file, O_BINARY | O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR), "wb");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user