Boost logo

Boost :

From: Beman Dawes (bdawes_at_[hidden])
Date: 2002-12-17 16:59:45


At 04:42 AM 12/17/2002, Vladimir Prus wrote:
>
>Beman Dawes wrote:
>
> > >6. Would it be reasonable to introduce a function
>"create_directories",
> > > similiar in spirit to "remove_all"? That function would create
> > > intermediate directories, not only the leaf one.
> >
> > Yes, that would be both reasonable and useful. The
> > filesystem/convenience.hpp header we've discussed would be a good
place.
>
>Agreed. BTW, where would that header live? In CVS tree or in sandbox? And
>what would be the access rules?
>
> >
> > Care to contribute it?
>
>See attachment.

Nice!

> A pretty trivial excersice, of course, except for one
>point. The create_directories function as written by me does nothing (not

>throws) if you call it on existing directory. And explicit "exists" all
is
>certainly needed for parent directories, and I'm not sure what to do with
>the full directory.
>
>Allowing it to exist seems in spirit of this function --- after all it
>automatically creates needed directories and does nothing with already
>existing.

Yes, I think so too.

How about the following? Note that moving the "exists" up also prevents
the problem of trying to create_directories on the root directory.

     void create_directories(const path& ph)
     {
         if (ph.empty() || exists(ph))
             return;

         // First create branch, by calling ourself recursively
         create_directories(ph.branch_path());
         // Now that parent's path exists, create the directory
         create_directory(ph);
     }

>OTOH, this behaviour is different from 'create_directory', which throws
if
>directory does not exist.

No different from remove/remove_all. The convenience functions should be
just that; convenient. Worrying about consistency produces a less useful
interface.

>Lastly, we probably can't change create_directory, at least for one
reason.
>On Linux, this operation is atomic, and can be used to make locks. I
guess,
>the same is true on Windows. If 'create_directory' checks for
existence, >you cannot use it for locking any more.
>
>So, what's the right interface?

See above.

Thanks,

--Beman


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