Re: [boost] [Filesystem] behaviour of branch_path

Why does branch_path return path("") with simple paths like "file.ext"? Would'nt it make more sense to return path(".")? At least that was I was expecting. I had to go carefully see at documentation to discover it wasn't like that, because in other place in the docs its writen "A non-empty
At 10:48 PM 1/25/2004, Gustavo Guerra wrote: path
is specified as a precondition because an empty path is almost certainly an error".
This way, for example, if I have some code that gets the parent directory of a path and then uses that in other path operations, I'm forced to make
special cases checking for has_branch_path, when if it returned "." it would work better for most cases...
In thinking more about this need, it seems to me that changing path::branch_path() may not be the best approach. Class path member functions work only on the lexical representation of a path, regardless of the actual state of the external filesystem. The use cases I can think of usually need to look at the external filesystem. Also, The decomposition functions return elements of the path. It seems a bit surprising for a decomposition function to return "." when it is not an element of the path. Perhaps the use cases you are running into would be better dealt with by new operational functions which do look at filesystem state. Two possible functions come to mind (subject to better naming): path directory_path_of_file( const path & ph ); Throws: !exists(ph) || is_directory(ph) Returns: branch_path(ph).empty() ? path(".") : branch_path(ph) path directory_path( const path & ph ); Throws: !exists(ph) Returns: is_directory(ph) ? ph : directory_path_of_file(ph) Thoughts? --Beman
participants (1)
-
Beman Dawes