Bug 682912

Summary: wget -O truncates the output file before attempting the download.
Product: Red Hat Enterprise Linux 5 Reporter: Guil Barros <gbarros>
Component: wgetAssignee: Karsten Hopp <karsten>
Status: CLOSED NOTABUG QA Contact: BaseOS QE - Apps <qe-baseos-apps>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 5.6   
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-03-08 12:44:12 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Guil Barros 2011-03-07 23:21:12 UTC
Description of problem:
# wget -O /etc/resolv.conf "http://people.redhat.com/gbarros/blah"
will truncate the output file before doing the dns lookup, thus failing and trashing the file.

open("/etc/resolv.conf", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 3


Version-Release number of selected component (if applicable):
wget-1.11.4-2.el5_4.1.x86_64

How reproducible:
every time

Steps to Reproduce:
1. wget -O /etc/resolv.conf "http://people.redhat.com/gbarros/blah"
  
Actual results:
-O file gets clobbered

Expected results:
File is downloaded to a temporary location and moved into place when the download is complete.

Comment 1 Karsten Hopp 2011-03-08 12:44:12 UTC
That's expected and documented behaviour, this is from the man page:

Use of -O is not intended to mean simply "use the name file instead of the one in the URL;" rather, it is analogous to shell redirection: wget -O file http://foo is intended to work like wget -O - http://foo > file; file will be truncated immediately, and all downloaded content will be written there.