cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: Re: cURL TODO : 15.3 prevent file overwriting

From: Deepak Singh <deepak.sn_at_samsung.com>
Date: Tue, 27 May 2014 08:54:47 +0000 (GMT)
Samsung Enterprise Portal mySingle

Dear Daniel,

I agree with the changes suggested by you and sending the new patch.

Please find attached the patch with following changes:

> This is an attempt to fix one of the TO DO list activities in cURL.

>> Problem: 15.3 prevent file overwriting: Add an option that prevents cURL
>> from overwriting existing local files. When used, and there already is an
>> existing file with the target file name (either -O or -o), a number should
>> be appended (and increased if already existing). So that index.html becomes
>> first index.html.1 and then index.html.2 etc.

>Thanks for your contribution!

>I think it looks good. It needs a little fixing though but I don't see any
>major obstacles.

>> Solution: Added a new option 'n' which can be used with 'O' and 'o' options
>> to solve the above problem,

>We can't use 'n' for this since -n is already occupied. In your case your code
>works mostly due to a side-effect of the parsing code, but it is important
>that when using a single dash on the command line there can only be
>single-letter options. That means "-On" must equal "-O -n".

The list of options is very extensive and I was not able to find any suitable option for this.

Currently used '!' as the option with long name as 'no_clobber'.

I can not use "no-clobber" because "no-option" is used for disabling the boolean options.

Please suggest if you feel anything better.


>> - curl --remote-name-no-overwrite http://curl.haxx.se/docs/manpage.html

> Can we call it --remote-name-safe instead to make it a little shorter?

Agree, I have updated the code with : --remote-name-safe as the long name for option '-O!',

Some example usage of the above options:

- curl --remote-name-safe http://curl.haxx.se/docs/manpage.html

- curl -O! http://curl.haxx.se/docs/manpage.html

- curl -O -! http://curl.haxx.se/docs/manpage.html

- curl -O --no_clobber http://curl.haxx.se/docs/manpage.html

- curl -o <manpage.html> -! http://curl.haxx.se/docs/manpage.html

- curl -o <manpage.html> --no_clobber http://curl.haxx.se/docs/manpage.html


> Two things on the code:

> 1) Your code is also using sprintf() instead of the more proper snprintf()
> which would provide a boundary check.
Agree, I used it in our code.


> 2) There's a race condition in the code so if this would run on multiple
> instances it would end up overwriting a file anyway. I suggest you instead use
> open() and O_EXCL|O_CREAT so that it'll create the file if it doesn't exist
> and thus avoiding the race.
I have used fopen for reading only anyways, I have changed the fopen call with open.

Please provide your comments on above points.

Also, Since this is my first contribution in curl, Please correct me if I am missing something.


Thanks & Regards,

Deepak Singh

 

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html

201405271424744_QKNMBDIF.gif
Received on 2014-05-27