-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++] use copy_file_range for fs::copy #109211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2e871a9
[libc++] use copy_file_range for fs::copy_file
Jannik2099 6009df0
[libc++] support special linux files in fs::copy_file
Jannik2099 20f0bab
Minor reorganization per review comments
ldionne b697b46
Make _LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE and _LIBCPP_FILESYSTEM_US…
ldionne 79185fd
Fix incorrect semantics
ldionne 55fe8ca
fix bionic and no-locale config
Jannik2099 482ce86
set appropriate error_code when failing due to lack of fstream
Jannik2099 92765db
fix no-locale empty file copy
Jannik2099 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...x/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy_file/copy_file_procfs.pass.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++03, c++11, c++14 | ||
// REQUIRES: linux | ||
// UNSUPPORTED: no-filesystem | ||
// XFAIL: no-localization | ||
// UNSUPPORTED: availability-filesystem-missing | ||
|
||
// <filesystem> | ||
|
||
// bool copy_file(const path& from, const path& to); | ||
// bool copy_file(const path& from, const path& to, error_code& ec) noexcept; | ||
ldionne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// bool copy_file(const path& from, const path& to, copy_options options); | ||
// bool copy_file(const path& from, const path& to, copy_options options, | ||
// error_code& ec) noexcept; | ||
|
||
#include <cassert> | ||
Jannik2099 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#include <filesystem> | ||
#include <system_error> | ||
|
||
#include "test_macros.h" | ||
#include "filesystem_test_helper.h" | ||
|
||
namespace fs = std::filesystem; | ||
|
||
// Linux has various virtual filesystems such as /proc and /sys | ||
// where files may have no length (st_size == 0), but still contain data. | ||
// This is because the to-be-read data is usually generated ad-hoc by the reading syscall | ||
// These files can not be copied with kernel-side copies like copy_file_range or sendfile, | ||
// and must instead be copied via a traditional userspace read + write loop. | ||
int main(int, char** argv) { | ||
const fs::path procfile{"/proc/self/comm"}; | ||
assert(file_size(procfile) == 0); | ||
|
||
scoped_test_env env; | ||
std::error_code ec = GetTestEC(); | ||
|
||
const fs::path dest = env.make_env_path("dest"); | ||
|
||
assert(copy_file(procfile, dest, ec)); | ||
assert(!ec); | ||
|
||
// /proc/self/comm contains the filename of the executable, plus a null terminator | ||
assert(file_size(dest) == fs::path(argv[0]).filename().string().size() + 1); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.