mirror of
https://github.com/uutils/coreutils
synced 2024-11-17 02:08:09 +00:00
cp: close file descriptors after cow on linux
Instead of using into_raw_fd(), which transfers ownership and requires us to close the file descriptor manually, use as_raw_fd(), which does not transfer ownership to us but drops the file descriptor when the original file is dropped (in our case at the end of the function).
This commit is contained in:
parent
3cf966810f
commit
23f89d1494
1 changed files with 3 additions and 3 deletions
|
@ -41,7 +41,7 @@ use std::io;
|
|||
use std::io::{stdin, stdout, Write};
|
||||
use std::mem;
|
||||
#[cfg(target_os = "linux")]
|
||||
use std::os::unix::io::IntoRawFd;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
#[cfg(windows)]
|
||||
use std::os::windows::ffi::OsStrExt;
|
||||
use std::path::{Path, PathBuf, StripPrefixError};
|
||||
|
@ -1261,14 +1261,14 @@ fn copy_helper(source: &Path, dest: &Path, options: &Options) -> CopyResult<()>
|
|||
fn copy_on_write_linux(source: &Path, dest: &Path, mode: ReflinkMode) -> CopyResult<()> {
|
||||
debug_assert!(mode != ReflinkMode::Never);
|
||||
|
||||
let src_file = File::open(source).unwrap().into_raw_fd();
|
||||
let src_file = File::open(source).unwrap().as_raw_fd();
|
||||
let dst_file = OpenOptions::new()
|
||||
.write(true)
|
||||
.truncate(false)
|
||||
.create(true)
|
||||
.open(dest)
|
||||
.unwrap()
|
||||
.into_raw_fd();
|
||||
.as_raw_fd();
|
||||
match mode {
|
||||
ReflinkMode::Always => unsafe {
|
||||
let result = ficlone(dst_file, src_file as *const i32);
|
||||
|
|
Loading…
Reference in a new issue