@@ -1817,47 +1817,17 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
1817
1817
pub fn copy ( from : & Path , to : & Path ) -> io:: Result < u64 > {
1818
1818
use crate :: sync:: atomic:: { AtomicBool , Ordering } ;
1819
1819
1820
- const COPYFILE_ACL : u32 = 1 << 0 ;
1821
- const COPYFILE_STAT : u32 = 1 << 1 ;
1822
- const COPYFILE_XATTR : u32 = 1 << 2 ;
1823
- const COPYFILE_DATA : u32 = 1 << 3 ;
1824
-
1825
- const COPYFILE_SECURITY : u32 = COPYFILE_STAT | COPYFILE_ACL ;
1826
- const COPYFILE_METADATA : u32 = COPYFILE_SECURITY | COPYFILE_XATTR ;
1827
- const COPYFILE_ALL : u32 = COPYFILE_METADATA | COPYFILE_DATA ;
1828
-
1829
- const COPYFILE_STATE_COPIED : u32 = 8 ;
1830
-
1831
- #[ allow( non_camel_case_types) ]
1832
- type copyfile_state_t = * mut libc:: c_void ;
1833
- #[ allow( non_camel_case_types) ]
1834
- type copyfile_flags_t = u32 ;
1835
-
1836
- extern "C" {
1837
- fn fcopyfile (
1838
- from : libc:: c_int ,
1839
- to : libc:: c_int ,
1840
- state : copyfile_state_t ,
1841
- flags : copyfile_flags_t ,
1842
- ) -> libc:: c_int ;
1843
- fn copyfile_state_alloc ( ) -> copyfile_state_t ;
1844
- fn copyfile_state_free ( state : copyfile_state_t ) -> libc:: c_int ;
1845
- fn copyfile_state_get (
1846
- state : copyfile_state_t ,
1847
- flag : u32 ,
1848
- dst : * mut libc:: c_void ,
1849
- ) -> libc:: c_int ;
1850
- }
1851
-
1852
- struct FreeOnDrop ( copyfile_state_t ) ;
1820
+ const COPYFILE_ALL : libc:: copyfile_flags_t = libc:: COPYFILE_METADATA | libc:: COPYFILE_DATA ;
1821
+
1822
+ struct FreeOnDrop ( libc:: copyfile_state_t ) ;
1853
1823
impl Drop for FreeOnDrop {
1854
1824
fn drop ( & mut self ) {
1855
1825
// The code below ensures that `FreeOnDrop` is never a null pointer
1856
1826
unsafe {
1857
1827
// `copyfile_state_free` returns -1 if the `to` or `from` files
1858
1828
// cannot be closed. However, this is not considered this an
1859
1829
// error.
1860
- copyfile_state_free ( self . 0 ) ;
1830
+ libc :: copyfile_state_free ( self . 0 ) ;
1861
1831
}
1862
1832
}
1863
1833
}
@@ -1866,6 +1836,7 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
1866
1836
// We store the availability in a global to avoid unnecessary syscalls
1867
1837
static HAS_FCLONEFILEAT : AtomicBool = AtomicBool :: new ( true ) ;
1868
1838
syscall ! {
1839
+ // Mirrors `libc::fclonefileat`
1869
1840
fn fclonefileat(
1870
1841
srcfd: libc:: c_int,
1871
1842
dst_dirfd: libc:: c_int,
@@ -1902,22 +1873,22 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
1902
1873
// We ensure that `FreeOnDrop` never contains a null pointer so it is
1903
1874
// always safe to call `copyfile_state_free`
1904
1875
let state = unsafe {
1905
- let state = copyfile_state_alloc ( ) ;
1876
+ let state = libc :: copyfile_state_alloc ( ) ;
1906
1877
if state. is_null ( ) {
1907
1878
return Err ( crate :: io:: Error :: last_os_error ( ) ) ;
1908
1879
}
1909
1880
FreeOnDrop ( state)
1910
1881
} ;
1911
1882
1912
- let flags = if writer_metadata. is_file ( ) { COPYFILE_ALL } else { COPYFILE_DATA } ;
1883
+ let flags = if writer_metadata. is_file ( ) { COPYFILE_ALL } else { libc :: COPYFILE_DATA } ;
1913
1884
1914
- cvt ( unsafe { fcopyfile ( reader. as_raw_fd ( ) , writer. as_raw_fd ( ) , state. 0 , flags) } ) ?;
1885
+ cvt ( unsafe { libc :: fcopyfile ( reader. as_raw_fd ( ) , writer. as_raw_fd ( ) , state. 0 , flags) } ) ?;
1915
1886
1916
1887
let mut bytes_copied: libc:: off_t = 0 ;
1917
1888
cvt ( unsafe {
1918
- copyfile_state_get (
1889
+ libc :: copyfile_state_get (
1919
1890
state. 0 ,
1920
- COPYFILE_STATE_COPIED ,
1891
+ libc :: COPYFILE_STATE_COPIED as u32 ,
1921
1892
core:: ptr:: addr_of_mut!( bytes_copied) as * mut libc:: c_void ,
1922
1893
)
1923
1894
} ) ?;
0 commit comments