Boost logo

Boost :

From: Robert Bell (belvis_at_[hidden])
Date: 2004-03-09 14:12:10


Jeff Garland wrote:
> On Tue, 09 Mar 2004 11:36:52 -0500, Beman Dawes wrote
>
>>That's an interesting thought. Of course, it might not be another
>>thread but rather another process that created the directory, and
>>that could be a sign of real trouble.
>>
>>But such a change would allow simpler user code. What is now written:
>>
>> if ( !exists( foo ) ) create_directory( foo );
>>
>>becomes:
>>
>> create_directory( foo );
>>
>>
>>What happens when the directory existing really does constitute and
>>error, and create_directory() doesn't throw? Will applications fail
>>in difficult to diagnose ways? Can applications protect themselves
>>against silent failure?
>
>
> How about something like:
> void create_directory ( const path& name, bool error_if_exists = false);
>
> Then the application can decide -- defaulting to nothrow.

I agree; the application must be able to decide if the directory
existing is an error condition or not. However, I don't like the
optional argument. I think I would have a hard time remembering whether
it was

void create_directory(const path& name, bool ok_if_exists = true);

or

void create_directory(const path& name, bool error_if_exists = false);

create_directory(path, true); // ???

Instead I would prefer two separately named functions, like
create_directory() and create_directory_exists_ok(). (Well, maybe not
these two names exactly, but you get the idea. ;-) )

In the past I've used the word "soft" for this kind of thing:

create_directory -- throws if directory already exists
soft_create_directory -- doesn't throw if directory already exists

>>What happens if the path exists but is not a directory? Presumably
>>that case must still throw.
>
>
> Yes, I think so.

I agree.

Just my $0.02.

Bob


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk