Modify

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#6932 closed Bugs (fixed)

create_directories throws exception even if error_code is specified

Reported by: xuefer@… Owned by: bemandawes
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

Attachments (0)

Change History (4)

comment:1 Changed 5 years ago by xuefer@…

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

comment:2 Changed 5 years ago by bemandawes

  • Resolution set to fixed
  • Status changed from new to closed

(In [78721]) Filesystem: fix #6932, create_directories throws exception even if error_code is specified.

comment:3 Changed 5 years ago by xuefer@…

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.

comment:4 Changed 5 years ago by bemandawes

See 78747.

--Beman

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain bemandawes.
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.