diff --git a/NEWS b/NEWS index 5073d7e..56c21a5 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,12 @@ See the end for copying conditions. Please send GNU Wget bug reports to . +* 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 56b8669..3cafd1c 100644 --- a/src/http.c +++ b/src/http.c @@ -39,6 +39,7 @@ as that of the covered work. */ #include #include #include +#include #include "hash.h" #include "http.h" @@ -1568,6 +1569,7 @@ struct http_stat #ifdef HAVE_METALINK metalink_t *metalink; #endif + bool temporary; /* downloading a temporary file */ }; static void @@ -2258,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)) { @@ -2471,7 +2482,15 @@ 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 */ - *fp = fopen (hs->local_file, "wb"); + if (hs->temporary) + { + *fp = fdopen (open (hs->local_file, O_BINARY | O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR), "wb"); + } + else + { + *fp = fopen (hs->local_file, "wb"); + } + #endif /* def __VMS [else] */ } else