boost::filesystem::create_directories(".")
always fails on my system. It seems like this might be a bug, but after reading the documentation I'm not entirely sure. Here's an example program:
#include <iostream>
#include <boost/filesystem.hpp>
int main(int argc, char* argv[])
try
{
namespace fs = boost::filesystem;
std::cerr << "is_directory: " << fs::is_directory(argv[1]) << '\n';
std::cerr << "create_directory: " << fs::create_directory(argv[1]) << '\n';
std::cerr << "create_directories: " << fs::create_directories(argv[1]) << '\n';
}
catch (const std::exception& ex)
{
std::cerr << ex.what() << '\n';
}
If I run this with the argument .
(meaning the current directory), it prints:
is_directory: 1
create_directory: 0
boost::filesystem::create_directories: Invalid argument
The first two lines are unsurprising: .
is a directory, and create_directory()
is documented saying:
Creation failure because p resolves to an existing directory shall not be treated as an error.
But the third line is a surprise to me: create_directories(".")
failed even though .
exists. There is no such failure if you use a different name, like foo
- it will happily create that directory or just return false if it exists already.
The docs have this to say:
Effect: Establishes the postcondition by calling create_directory() for any element of p that does not exist.
Postcondition: is_directory(p)
We have shown that the postcondition is true beforehand, so why does it fail?
Edit: I'm using Boost 1.63. I see now that a commit three months ago to "Fix #12495" probably causes this problem: https://github.com/boostorg/filesystem/commit/216720de55359828c2dc915b50e6ead44e00cd15 - and even includes a unit test which demands that create_directories(".")
must fail while create_directory(".")
must succeed, which is bizarre .