#6932 closed Bugs (fixed)
create_directories throws exception even if error_code is specified
| Reported by: | Owned by: | Beman Dawes | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | filesystem |
| Version: | Boost 1.49.0 | Severity: | Problem |
| Keywords: | Cc: |
Description
code
boost::system::error_code errorCode; fs::create_directories(backupDirectory, errorCode);
error
Unhandled exception at 0x75c5b9bc in UsbPhoneWD.exe: Microsoft C++ exception: boost::filesystem3::filesystem_error at memory location 0x0257b6d0..
backtrace
> a.exe!`anonymous namespace'::process_status_failure(const boost::filesystem3::path & p, boost::system::error_code * ec) Line 623 + 0x4b bytes C++ a.exe!boost::filesystem3::detail::status(const boost::filesystem3::path & p, boost::system::error_code * ec) Line 1627 + 0x11 bytes C++ a.exe!boost::filesystem3::exists(const boost::filesystem3::path & p) Line 289 + 0x30 bytes C++ a.exe!boost::filesystem3::detail::create_directories(const boost::filesystem3::path & p, boost::system::error_code * ec) Line 927 + 0x18 bytes C++ a.exe!boost::filesystem3::create_directories(const boost::filesystem3::path & p, boost::system::error_code & ec) Line 403 + 0x2b bytes C++
boost::filesystem3::detail::create_directories Line 927
BOOST_FILESYSTEM_DECL
bool create_directories(const path& p, system::error_code* ec)
{
if (p.empty() || exists(p)) <- this is Line 927
{
if (!p.empty() && !is_directory(p))
{
if (ec == 0)
BOOST_FILESYSTEM_THROW(filesystem_error(
"boost::filesystem::create_directories", p,
error_code(system::errc::file_exists, system::generic_category())));
else ec->assign(system::errc::file_exists, system::generic_category());
}
return false;
}
// First create branch, by calling ourself recursively
create_directories(p.parent_path(), ec);
// Now that parent's path exists, create the directory
create_directory(p, ec);
return true;
}
maybe "error_code dummy" should be pass to exists() and is_directory() to avoid throwing exception, just like create_directory do
Change History (4)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
comment:3 by , 10 years ago
before i make some time to test it, i doubt this patch, are you sure it is fixed and the test passes?
the exception is thrown by exists() call because no error_code is pass to it (check the call stack (the backtrace) i post).
in [78721], create_directories still call exists(p) not error_code dummy; exists(p, dummy) like create_directory do currently.
Note:
See TracTickets
for help on using tickets.

btw, it is reproduced when backupDirectory is a directory that has empty permission, every single permission is removed from the directory. (NTFS)