| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// UNSUPPORTED: c++03, c++11, c++14 |
| 10 |
// REQUIRES: linux |
| 11 |
// UNSUPPORTED: no-filesystem |
| 12 |
// XFAIL: no-localization |
| 13 |
|
| 14 |
// <filesystem> |
| 15 |
|
| 16 |
// bool copy_file(const path& from, const path& to); |
| 17 |
// bool copy_file(const path& from, const path& to, error_code& ec) noexcept; |
| 18 |
// bool copy_file(const path& from, const path& to, copy_options options); |
| 19 |
// bool copy_file(const path& from, const path& to, copy_options options, |
| 20 |
// error_code& ec) noexcept; |
| 21 |
|
| 22 |
#include <cassert> |
| 23 |
#include <filesystem> |
| 24 |
#include <system_error> |
| 25 |
|
| 26 |
#include "test_macros.h" |
| 27 |
#include "filesystem_test_helper.h" |
| 28 |
|
| 29 |
namespace fs = std::filesystem; |
| 30 |
|
| 31 |
// Linux has various virtual filesystems such as /proc and /sys |
| 32 |
// where files may have no length (st_size == 0), but still contain data. |
| 33 |
// This is because the to-be-read data is usually generated ad-hoc by the reading syscall |
| 34 |
// These files can not be copied with kernel-side copies like copy_file_range or sendfile, |
| 35 |
// and must instead be copied via a traditional userspace read + write loop. |
| 36 |
int main(int, char** argv) { |
| 37 |
const fs::path procfile{"/proc/self/comm"}; |
| 38 |
assert(file_size(procfile) == 0); |
| 39 |
|
| 40 |
scoped_test_env env; |
| 41 |
std::error_code ec = GetTestEC(); |
| 42 |
|
| 43 |
const fs::path dest = env.make_env_path("dest"); |
| 44 |
|
| 45 |
assert(copy_file(procfile, dest, ec)); |
| 46 |
assert(!ec); |
| 47 |
|
| 48 |
// /proc/self/comm contains the filename of the executable, plus a null terminator |
| 49 |
assert(file_size(dest) == fs::path(argv[0]).filename().string().size() + 1); |
| 50 |
|
| 51 |
return 0; |
| 52 |
} |