Skip to content
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

Rollup of 9 pull requests #126891

Merged
merged 20 commits into from
Jun 24, 2024
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
65530ba
std::unix::fs: copy simplification for apple.
devnexen Jun 21, 2024
9905357
cargo update
invalid-email-address Jun 23, 2024
e8b5ba1
For [E0308]: mismatched types, when expr is in an arm's body, not add…
surechen Jun 14, 2024
0d8f734
compiler: Fix arm32 asm issues by hierarchically sorting reg classes
workingjubilee Jun 23, 2024
bd9ce3e
std::unix::os::home_dir: fallback's optimisation.
devnexen Jun 23, 2024
fc50aca
fix build
devnexen Jun 23, 2024
03d73fa
ci: Add support for dist-loongarch64-musl
heiher Mar 5, 2024
16fef40
Promote loongarch64-unknown-linux-musl to Tier 2 with host tools
heiher Nov 13, 2023
a426d6f
Implement use<> formatting in rustfmt
compiler-errors Jun 20, 2024
a23917c
Add hard error and migration lint for unsafe attrs
carbotaniuman Jun 8, 2024
25446c2
Remove stray println from rustfmt
compiler-errors Jun 24, 2024
9a591ea
Rollup merge of #126177 - carbotaniuman:unsafe_attr_errors, r=jieyouxu
matthiaskrgr Jun 24, 2024
7babf99
Rollup merge of #126298 - heiher:loongarch64-musl-ci, r=Mark-Simulacrum
matthiaskrgr Jun 24, 2024
ad0531a
Rollup merge of #126455 - surechen:fix_126222, r=estebank
matthiaskrgr Jun 24, 2024
b24e3df
Rollup merge of #126754 - compiler-errors:use-rustfmt, r=calebcartwright
matthiaskrgr Jun 24, 2024
21850f5
Rollup merge of #126807 - devnexen:copy_file_macos_simpl, r=Mark-Simu…
matthiaskrgr Jun 24, 2024
dcace86
Rollup merge of #126845 - rust-lang:cargo_update, r=Mark-Simulacrum
matthiaskrgr Jun 24, 2024
3108dfa
Rollup merge of #126849 - workingjubilee:correctly-classify-arm-low-d…
matthiaskrgr Jun 24, 2024
9892b3e
Rollup merge of #126854 - devnexen:std_unix_os_fallback_upd, r=Mark-S…
matthiaskrgr Jun 24, 2024
b94d275
Rollup merge of #126888 - compiler-errors:oops-debug-printing, r=dtolnay
matthiaskrgr Jun 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
std::unix::fs: copy simplification for apple.
since we do support from macOs Sierra, we avoid the little runtime overhead
with the fclonefileat symbol check.
  • Loading branch information
devnexen committed Jun 21, 2024
commit 65530ba100a6cde650a0075d3644c973f51da818
50 changes: 15 additions & 35 deletions library/std/src/sys/pal/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ use crate::sys::time::SystemTime;
use crate::sys::{cvt, cvt_r};
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};

#[cfg(any(all(target_os = "linux", target_env = "gnu"), target_vendor = "apple"))]
#[cfg(all(target_os = "linux", target_env = "gnu"))]
use crate::sys::weak::syscall;
#[cfg(target_os = "android")]
use crate::sys::weak::weak;

use libc::{c_int, mode_t};

#[cfg(any(all(target_os = "linux", target_env = "gnu"), target_vendor = "apple"))]
#[cfg(all(target_os = "linux", target_env = "gnu"))]
use libc::c_char;
#[cfg(any(
all(target_os = "linux", not(target_env = "musl")),
Expand Down Expand Up @@ -1891,8 +1891,6 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {

#[cfg(target_vendor = "apple")]
pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
use crate::sync::atomic::{AtomicBool, Ordering};

const COPYFILE_ALL: libc::copyfile_flags_t = libc::COPYFILE_METADATA | libc::COPYFILE_DATA;

struct FreeOnDrop(libc::copyfile_state_t);
Expand All @@ -1907,39 +1905,21 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
}
}

// MacOS prior to 10.12 don't support `fclonefileat`
// We store the availability in a global to avoid unnecessary syscalls
static HAS_FCLONEFILEAT: AtomicBool = AtomicBool::new(true);
syscall! {
// Mirrors `libc::fclonefileat`
fn fclonefileat(
srcfd: libc::c_int,
dst_dirfd: libc::c_int,
dst: *const c_char,
flags: libc::c_int
) -> libc::c_int
}

let (reader, reader_metadata) = open_from(from)?;

// Opportunistically attempt to create a copy-on-write clone of `from`
// using `fclonefileat`.
if HAS_FCLONEFILEAT.load(Ordering::Relaxed) {
let clonefile_result = run_path_with_cstr(to, &|to| {
cvt(unsafe { fclonefileat(reader.as_raw_fd(), libc::AT_FDCWD, to.as_ptr(), 0) })
});
match clonefile_result {
Ok(_) => return Ok(reader_metadata.len()),
Err(err) => match err.raw_os_error() {
// `fclonefileat` will fail on non-APFS volumes, if the
// destination already exists, or if the source and destination
// are on different devices. In all these cases `fcopyfile`
// should succeed.
Some(libc::ENOTSUP) | Some(libc::EEXIST) | Some(libc::EXDEV) => (),
Some(libc::ENOSYS) => HAS_FCLONEFILEAT.store(false, Ordering::Relaxed),
_ => return Err(err),
},
}
let clonefile_result = run_path_with_cstr(to, &|to| {
cvt(unsafe { libc::fclonefileat(reader.as_raw_fd(), libc::AT_FDCWD, to.as_ptr(), 0) })
});
match clonefile_result {
Ok(_) => return Ok(reader_metadata.len()),
Err(e) => match e.raw_os_error() {
// `fclonefileat` will fail on non-APFS volumes, if the
// destination already exists, or if the source and destination
// are on different devices. In all these cases `fcopyfile`
// should succeed.
Some(libc::ENOTSUP) | Some(libc::EEXIST) | Some(libc::EXDEV) => (),
_ => return Err(e),
},
}

// Fall back to using `fcopyfile` if `fclonefileat` does not succeed.
Expand Down
Loading