@@ -1847,47 +1847,17 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
1847
1847
pub fn copy ( from : & Path , to : & Path ) -> io:: Result < u64 > {
1848
1848
use crate :: sync:: atomic:: { AtomicBool , Ordering } ;
1849
1849
1850
- const COPYFILE_ACL : u32 = 1 << 0 ;
1851
- const COPYFILE_STAT : u32 = 1 << 1 ;
1852
- const COPYFILE_XATTR : u32 = 1 << 2 ;
1853
- const COPYFILE_DATA : u32 = 1 << 3 ;
1854
-
1855
- const COPYFILE_SECURITY : u32 = COPYFILE_STAT | COPYFILE_ACL ;
1856
- const COPYFILE_METADATA : u32 = COPYFILE_SECURITY | COPYFILE_XATTR ;
1857
- const COPYFILE_ALL : u32 = COPYFILE_METADATA | COPYFILE_DATA ;
1858
-
1859
- const COPYFILE_STATE_COPIED : u32 = 8 ;
1860
-
1861
- #[ allow( non_camel_case_types) ]
1862
- type copyfile_state_t = * mut libc:: c_void ;
1863
- #[ allow( non_camel_case_types) ]
1864
- type copyfile_flags_t = u32 ;
1865
-
1866
- extern "C" {
1867
- fn fcopyfile (
1868
- from : libc:: c_int ,
1869
- to : libc:: c_int ,
1870
- state : copyfile_state_t ,
1871
- flags : copyfile_flags_t ,
1872
- ) -> libc:: c_int ;
1873
- fn copyfile_state_alloc ( ) -> copyfile_state_t ;
1874
- fn copyfile_state_free ( state : copyfile_state_t ) -> libc:: c_int ;
1875
- fn copyfile_state_get (
1876
- state : copyfile_state_t ,
1877
- flag : u32 ,
1878
- dst : * mut libc:: c_void ,
1879
- ) -> libc:: c_int ;
1880
- }
1881
-
1882
- struct FreeOnDrop ( copyfile_state_t ) ;
1850
+ const COPYFILE_ALL : libc:: copyfile_flags_t = libc:: COPYFILE_METADATA | libc:: COPYFILE_DATA ;
1851
+
1852
+ struct FreeOnDrop ( libc:: copyfile_state_t ) ;
1883
1853
impl Drop for FreeOnDrop {
1884
1854
fn drop ( & mut self ) {
1885
1855
// The code below ensures that `FreeOnDrop` is never a null pointer
1886
1856
unsafe {
1887
1857
// `copyfile_state_free` returns -1 if the `to` or `from` files
1888
1858
// cannot be closed. However, this is not considered this an
1889
1859
// error.
1890
- copyfile_state_free ( self . 0 ) ;
1860
+ libc :: copyfile_state_free ( self . 0 ) ;
1891
1861
}
1892
1862
}
1893
1863
}
@@ -1896,6 +1866,7 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
1896
1866
// We store the availability in a global to avoid unnecessary syscalls
1897
1867
static HAS_FCLONEFILEAT : AtomicBool = AtomicBool :: new ( true ) ;
1898
1868
syscall ! {
1869
+ // Mirrors `libc::fclonefileat`
1899
1870
fn fclonefileat(
1900
1871
srcfd: libc:: c_int,
1901
1872
dst_dirfd: libc:: c_int,
@@ -1932,22 +1903,22 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
1932
1903
// We ensure that `FreeOnDrop` never contains a null pointer so it is
1933
1904
// always safe to call `copyfile_state_free`
1934
1905
let state = unsafe {
1935
- let state = copyfile_state_alloc ( ) ;
1906
+ let state = libc :: copyfile_state_alloc ( ) ;
1936
1907
if state. is_null ( ) {
1937
1908
return Err ( crate :: io:: Error :: last_os_error ( ) ) ;
1938
1909
}
1939
1910
FreeOnDrop ( state)
1940
1911
} ;
1941
1912
1942
- let flags = if writer_metadata. is_file ( ) { COPYFILE_ALL } else { COPYFILE_DATA } ;
1913
+ let flags = if writer_metadata. is_file ( ) { COPYFILE_ALL } else { libc :: COPYFILE_DATA } ;
1943
1914
1944
- cvt ( unsafe { fcopyfile ( reader. as_raw_fd ( ) , writer. as_raw_fd ( ) , state. 0 , flags) } ) ?;
1915
+ cvt ( unsafe { libc :: fcopyfile ( reader. as_raw_fd ( ) , writer. as_raw_fd ( ) , state. 0 , flags) } ) ?;
1945
1916
1946
1917
let mut bytes_copied: libc:: off_t = 0 ;
1947
1918
cvt ( unsafe {
1948
- copyfile_state_get (
1919
+ libc :: copyfile_state_get (
1949
1920
state. 0 ,
1950
- COPYFILE_STATE_COPIED ,
1921
+ libc :: COPYFILE_STATE_COPIED as u32 ,
1951
1922
core:: ptr:: addr_of_mut!( bytes_copied) as * mut libc:: c_void ,
1952
1923
)
1953
1924
} ) ?;
0 commit comments