[llvm-bugs] [Bug 43792] New: broken std::filesystem::copy_file().

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Oct 24 11:35:36 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=43792

            Bug ID: 43792
           Summary: broken std::filesystem::copy_file().
           Product: libc++
           Version: 9.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: pawel_sikora at zoho.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191024/4828f08e/attachment.html>


More information about the llvm-bugs mailing list