From: Beman Dawes (bdawes_at_[hidden])
Date: 2004-03-09 15:01:59
At 12:55 PM 3/9/2004, Peter Dimov wrote:
>Walter Landry wrote:
>> Beman Dawes <bdawes_at_[hidden]> wrote:
>>> At 01:55 AM 3/9/2004, Vladimir Prus wrote:
>>> >After all, caller only cares if directory exists, if it was
>>> created by >another thread it's ok.
>>> 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.
>> Exactly. Normally people use lock-files, but I personally have a use
>> for lock-directories. If boost::filesystem starts swallowing errors,
>> it makes it more difficult to achieve that.
>It doesn't have to swallow errors. It can simply signal some errors via
>exceptions and some errors via return values.
>> I would say that people who don't care whether a directory is created
>> should just catch the exception themselves. Alternately, you could
>> generalize make_directory to take an extra, optional argument that
>> specifies whether to throw if the directory already exists. Of
>> course, it should always throw if the error is something different
>> (e.g. if the parent directory doesn't exist).
>This almost goes without saying.
> create_directory(path p)
> post: p exists and is a directory
>If the postcondition cannot be satisfied, create_directory _must_ throw.
>But if p already exists and is a directory, the postcondition already
>holds, so we are free to report the "error" via a different mechanism
>(COM, for example, has a conventional "alternate success code" S_FALSE
>for such situations).
We have a similar case with remove(), which is reported by remove()
returning a bool indicating if it actually removed anything.
It would be quite consistent for create_directory() to return a bool
indicating if it actually had to create the directory.
Boost list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk