Avis, Ed wrote:
>If you try to download a file with wget and the download fails, then
>normally wget writes no output.
>
>% wget --quiet http://www.gnu.org/nonexistent
>% ls -l nonexistent
>ls: nonexistent: No such file or directory
>
>This is good behaviour. It would be confusing to create the output file
>when nothing has been downloaded. But with the -O option, wget creates
>an output file whether successful or not:
>
>% wget -O out --quiet http://www.gnu.org/nonexistent
>% ls -l out
>-rw-rw-r-- 1 avised avised 0 2006-01-17 08:57 out
>
>I think that the behaviour with -O should be consistent with the
>behaviour without -O, that is, no output file should be created in the
>case of 404 errors or other total failures to download anything.
>
>
the following patch (just commited into the trunk) should solve the
problem. i am not so sure that checking that the amount of downloaded
bytes is zero is a safe condition for the removal of the output
document. a better solution would probably be to count the actual number
of successful downloads, to avoid the deletion of valid zero-sized
resources when -O is used.
Index: init.c
===================================================================
--- init.c (revision 2104)
+++ init.c (working copy)
@@ -1427,7 +1427,15 @@
/* Free external resources, close files, etc. */
if (output_stream)
- fclose (output_stream);
+ {
+ fclose (output_stream);
+ if (opt.output_document
+ && !(total_downloaded_bytes > 0))
+ {
+ unlink (opt.output_document);
+ }
+ }
+
/* No need to check for error because Wget flushes its output (and
checks for errors) after any data arrives. */
--
Aequam memento rebus in arduis servare mentem...
Mauro Tortonesi http://www.tortonesi.com
University of Ferrara - Dept. of Eng. http://www.ing.unife.it
GNU Wget - HTTP/FTP file retrieval tool http://www.gnu.org/software/wget
Deep Space 6 - IPv6 for Linux http://www.deepspace6.net
Ferrara Linux User Group http://www.ferrara.linux.it