<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - broken std::filesystem::copy_file()."
href="https://bugs.llvm.org/show_bug.cgi?id=43792">43792</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>broken std::filesystem::copy_file().
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>9.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>pawel_sikora@zoho.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
</td>
</tr></table>
<p>
<div>
<pre>hi,
i'm observing many 'Invalid argument'/'Bad file descriptor' exceptions during
copy_file() on the multiprocessor servers. please consider following testcase:
#include "UnitTest++.h"
#include <array>
// #include <boost/filesystem.hpp>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <sstream>
#include <thread>
SUITE( filesystem ) {
TEST( copy_file_hello ) {
std::filesystem::path src( "foo.txt" );
std::ofstream hello( src );
hello << "hello world.\n";
hello.close();
auto fn = [&]( unsigned i ) -> void {
std::filesystem::path dstDir = "bar_" + std::to_string( i );
std::filesystem::remove_all( dstDir );
std::filesystem::create_directories( dstDir );
std::filesystem::path dst = dstDir / "bar.txt";
for ( unsigned n = 0; n < 100; n++ ) {
try {
std::filesystem::copy_file( src, dst,
std::filesystem::copy_options::overwrite_existing );
// boost::filesystem::copy_file( src.string(),
dst.string(),
// boost::filesystem::copy_option::overwrite_if_exists );
} catch ( std::exception const& e ) {
std::ostringstream oss;
oss << "exception: {" << e.what() << "} in thread {" <<
std::hex << std::this_thread::get_id() << "} in " << n
<< "-nth iteration\n";
std::cerr << oss.str();
return;
}
}
};
std::array< std::thread, 16 > ths;
unsigned i = 0;
for ( std::thread& th : ths ) {
th = std::thread( fn, i++ );
}
for ( std::thread& th : ths ) {
th.join();
}
}
}
std::filessytem::copy_file() results:
exception: {filesystem error: in copy_file: Bad file descriptor [bar_1/bar.txt]
[foo.txt]} in thread {7fd52e30b700} in 1-nth iteration
exception: {filesystem error: in copy_file: Bad file descriptor [bar_3/bar.txt]
[foo.txt]} in thread {7fd52d309700} in 2-nth iteration
exception: {filesystem error: in copy_file: Bad file descriptor [bar_5/bar.txt]
[foo.txt]} in thread {7fd52c307700} in 0-nth iteration
exception: {filesystem error: in copy_file: Bad file descriptor
[bar_10/bar.txt] [foo.txt]} in thread {7fd529b02700} in 0-nth iteration
exception: {filesystem error: in copy_file: Invalid argument [bar_7/bar.txt]
[foo.txt]} in thread {7fd52b305700} in 0-nth iteration
exception: {filesystem error: in copy_file: Bad file descriptor
[bar_13/bar.txt] [foo.txt]} in thread {7fd528b00700} in 0-nth iteration
exception: {filesystem error: in copy_file: Invalid argument [bar_8/bar.txt]
[foo.txt]} in thread {7fd52ab04700} in 2-nth iteration
exception: {filesystem error: in copy_file: Invalid argument [bar_12/bar.txt]
[foo.txt]} in thread {7fd529301700} in 2-nth iteration
exception: {filesystem error: in copy_file: Invalid argument [bar_0/bar.txt]
[foo.txt]} in thread {7fd52eb0c700} in 2-nth iteration
exception: {filesystem error: in copy_file: Invalid argument [bar_15/bar.txt]
[foo.txt]} in thread {7fd522ffd700} in 3-nth iteration
exception: {filesystem error: in copy_file: Bad file descriptor
[bar_14/bar.txt] [foo.txt]} in thread {7fd5237fe700} in 3-nth iteration
exception: {filesystem error: in copy_file: Invalid argument [bar_4/bar.txt]
[foo.txt]} in thread {7fd52cb08700} in 4-nth iteration
exception: {filesystem error: in copy_file: Bad file descriptor [bar_6/bar.txt]
[foo.txt]} in thread {7fd52bb06700} in 4-nth iteration
exception: {filesystem error: in copy_file: Invalid argument [bar_2/bar.txt]
[foo.txt]} in thread {7fd52db0a700} in 3-nth iteration
exception: {filesystem error: in copy_file: Bad file descriptor
[bar_11/bar.txt] [foo.txt]} in thread {7fd523fff700} in 6-nth iteration
exception: {filesystem error: in copy_file: Bad file descriptor [bar_9/bar.txt]
[foo.txt]} in thread {7fd52a303700} in 7-nth iteration
on the other side, the boost::filesystem::copy_file() works fine.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>