korbes
korbes

Reputation: 1353

What error codes should I expect from Boost::filesystem::copy

I'm trying to copy a file to a destination using boost::filesystem::copy_file with the system::error_code parameter, as I don't want exceptions thrown.

That function accepts a parameter whether it should fail if a file already exists with the same name, which is the behavior I want. From http://www.boost.org/doc/libs/1_46_1/libs/filesystem/v3/doc/reference.html#copy_file:

Effects: If option == copy_option::fail_if_exists && exists(to), an error is reported.

However, I can't find which error codes I should expect. Is that dependent on the underlying OS?

Upvotes: 4

Views: 1153

Answers (1)

rhashimoto
rhashimoto

Reputation: 15841

Yes, it is dependent on the underlying OS. The source code shows that copy_file() (and other operations) generates errors like this:

  if (ec == 0)
    BOOST_FILESYSTEM_THROW(filesystem_error(message,
      p, error_code(BOOST_ERRNO, system_category())));
  else
    ec->assign(BOOST_ERRNO, system_category());

system_category() specifies errors originating from the operating system and BOOST_ERRNO on Posix systems is errno.

On Posix, the underlying call to open() with O_CREAT and O_EXCL will fail and set errno to EEXIST when the file already exists.

Upvotes: 2

Related Questions