does not create empty files with -o #183

Closed
joeyh opened this Issue Mar 27, 2015 · 7 comments

Projects

None yet

3 participants

@joeyh
joeyh commented Mar 27, 2015

I'd expect curl -o to always create the specified file, if the url download succeeded. This consistency means it's easy to use it in a script; run curl, check its exit status and if it succeeded, the url content is there in the file to be used. And it just seems to make sense. But, reality is different when downloading an url that happens to be empty:

joey@darkstar:>curl -o hello http://tmp.kitenet.net/empty
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:- 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:- 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
joey@darkstar:
>cat hello
cat: hello: No such file or directory

This behavior is not documented on the man page either. So you have either a behavior bug (IMHO) or at least a documentation bug.

I'm using curl 7.38.0.

@bagder
Member
bagder commented Mar 27, 2015

It certainly works like this on purpose, it is not a mistake. The documentation should probably be clarified to make this less surprising.

The idea is to not create a file in case of errors so it creates the file on demand when the first data arrives. But if no data ever arrives...

@bagder bagder added the cmdline tool label Mar 27, 2015
@bagder bagder self-assigned this Mar 27, 2015
@joeyh
joeyh commented Mar 27, 2015

Daniel Stenberg wrote:

It certainly works like this on purpose, it is not a mistake. The documentation
should probably be clarified to make this less surprising.

The idea is to not create a file in case of errors so it creates the file on
demand when the first data arrives. But if no data ever arrives...

Seems like you could create the file once the data transfer is complete,
if it's not been created already on demand. I think that would be better
than documenting a complicating special case.

see shy jo

@kdudka
Collaborator
kdudka commented Mar 28, 2015

The current behavior sounds counter-intuitive to me, too. I would expect that successful download of a remote empty file results in a local empty file.

@bagder
Member
bagder commented Mar 28, 2015

I wouldn't mind having it create the file if it ends successfully!

@bagder
Member
bagder commented Mar 29, 2015

@joeyh feel like making a patch for it?

@kdudka
Collaborator
kdudka commented Mar 30, 2015

I have proposed a patch for this on the mailing-list:

http://thread.gmane.org/gmane.comp.web.curl.library/45327/focus=45328

@kdudka kdudka added a commit that referenced this issue Apr 8, 2015
@kdudka kdudka src/tool_operate: create output file on successful download
... of an empty file

Bug: #183
261a0fe
@kdudka
Collaborator
kdudka commented Apr 8, 2015

I have merged the fix for this issue: a9e4674...992a731

@kdudka kdudka closed this Apr 8, 2015
@jgsogo jgsogo added a commit to jgsogo/curl that referenced this issue Oct 19, 2015
@kdudka @jgsogo kdudka + jgsogo src/tool_operate: create output file on successful download
... of an empty file

Bug: curl#183
a6bb75e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment