Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

does not create empty files with -o #183

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

does not create empty files with -o #183

joeyh opened this issue Mar 27, 2015 · 7 comments
Assignees

Comments

@joeyh
Copy link

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
Copy link
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 self-assigned this Mar 27, 2015
@joeyh
Copy link
Author

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
Copy link
Contributor

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
Copy link
Member

bagder commented Mar 28, 2015

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

@bagder
Copy link
Member

bagder commented Mar 29, 2015

@joeyh feel like making a patch for it?

@kdudka
Copy link
Contributor

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 added a commit that referenced this issue Apr 8, 2015
@kdudka
Copy link
Contributor

kdudka commented Apr 8, 2015

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

3 participants