[英]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. 我正在尝试使用带有system :: error_code参数的boost :: filesystem :: copy_file将文件复制到目标,因为我不想抛出异常。
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 :
来自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.
效果:如果option == copy_option :: fail_if_exists && exists(to),则报告错误。
However, I can't find which error codes I should expect. 但是,我找不到我应该期待的错误代码。 Is that dependent on the underlying OS?
这取决于底层操作系统吗?
Yes, it is dependent on the underlying OS. 是的,它取决于底层操作系统。 The source code shows that
copy_file()
(and other operations) generates errors like this: 源代码显示
copy_file()
(和其他操作)生成如下错误:
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
. system_category()
指定源自操作系统的错误 ,Posix系统上的BOOST_ERRNO
是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. 在Posix上,使用
O_CREAT
和O_EXCL
对open()
的底层调用将失败,并在文件已存在时将errno
为EEXIST
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.