From 23f89d1494b0fa071adca1552ad6757f21e40b39 Mon Sep 17 00:00:00 2001 From: Michael Debertol Date: Tue, 1 Jun 2021 22:04:19 +0200 Subject: [PATCH] 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). --- src/uu/cp/src/cp.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index b7c64928f..3a5941284 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -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);