
At 01:55 AM 3/9/2004, Vladimir Prus wrote:
After more though, I wonder if create_directories should not swallow exceptions itself. E.g.
try { create_directory(ph); } catch(const filesystem_error& e) { if (e.error() == filesystem::already_exists_error) ; // do nothing else throw; }
Note that the actual implementation would not use a try/catch, but would have the same effect as your code.
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. 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? It seems to me some applications will expect directory foo to be empty, and might otherwise fail, but that this isn't a commonplace problem. Applications can detect that a directory is empty, although because of possible race conditions such a test could be misleading. But that's nothing new. Overall, it seems the change would be reasonably safe. What do others think? What happens if the path exists but is not a directory? Presumably that case must still throw. Thanks, --Beman