diff --git a/NEWS b/NEWS index 5073d7e8..56c21a58 100644 --- a/NEWS +++ b/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 diff --git a/src/http.c b/src/http.c index fd1abab4..3cafd1c4 100644 --- a/src/http.c +++ b/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"); }