|
Boost : |
From: Beman Dawes (bdawes_at_[hidden])
Date: 2002-03-28 13:33:21
At 08:53 AM 3/28/2002, Stewart, Robert wrote:
>> ...
>
>I find the progression confusing. The most restrictive semantics takes
no
>options, which is fine. Then, you relax the existence requirement with
an
>option, which is fine. Then, you add semantic behavior -- removing
>subdirectories, and any files -- with a single option. Finally, you
>subtract semantic behavior -- removing any files found -- by the addition
>of a second option.
>
>I would expect the addition of an option to tell remove() to remove files
>it happens to find, and the absence of that option to tell remove() to
>throw an exception if a directory is not empty.
Yes! Good catch!
> Thus, I'd expect "prune" -- or
>whatever name you may prefer -- to mean that the directory to remove need
>not be empty.
Well, "force" or "trim" are the words that come to mind. The copy
operation is going to need an option to indicate that it is OK to overwrite
existing target files. "force" would work for that, too. But something
that had the word "files" in it would be most explicit:
remove( "foo", including_files );
Well, we still need an option to indicate not to remove a directory that
isn't empty. I like "prune", but "if_empty" might be better:
remove( "foo", if_empty );
>
>Those points lead to this progression:
>
> // remove "foo," which must be empty and must exist
> remove("foo");
> // remove "foo," which must be empty but need not exist
> remove("foo", optional);
> // remove "foo," which may have subdirectories; all
> // directories must be empty
> remove("foo", recurse);
> // remove "foo," which may have subdirectories but need
> // not exist; all directories must be empty
> remove("foo", recurse + optional);
> // remove "foo," which may have subdirectories; any
> // directory may have files
> remove("foo", recurse + prune);
> // remove "foo," which may have subdirectories but need
> // not exist; any directory may have files
> remove("foo", recurse + prune + optional);
I think there are actually 16 valid combinations (optional|none,
recurse|none, include_files|none, if_empty|none), although two sets of
those produce duplicate behavior:
remove( "foo");
// remove "foo," which must be empty and must exist
remove( "foo", including_files );
// after removing any files in "foo", remove "foo",
// which must not contain any directories and must exist
remove( "foo", if_empty );
// if empty, remove "foo", which must exist
remove( "foo", including_files + if_empty);
// after removing any files in "foo", if empty, remove "foo",
// which must exist
remove( "foo", recurse );
// after depth-first recursive removal of any sub-directories,
// which must contain no files, remove "foo," which must exist
// and must contain no files.
remove( "foo", recurse + including_files );
// after depth-first recursive removal of any sub-directories,
// and any files files they contain, remove "foo," which must exist,
// and any files it contains.
remove( "foo", recurse + if_empty );
// after depth-first recursive removal of any empty sub-directories,
// remove "foo," which must exist, if it is empty.
remove( "foo", recurse + including_files + if_empty);
// same as remove( "foo", recurse + including_files );
// same as above, except "foo" need not exist
remove( "foo", optional );
remove( "foo", optional + including_files );
remove( "foo", optional + if_empty );
remove( "foo", optional + including_files + if_empty);
remove( "foo", optional + recurse );
remove( "foo", optional + recurse + including_files );
remove( "foo", optional + recurse + if_empty );
remove( "foo", optional + recurse + including_files + if_empty);
Thanks,
--Beman
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk