1 #![allow(dead_code)] // not used on all platforms
4 use crate::io
::{self, Error, ErrorKind}
;
7 pub fn copy(from
: &Path
, to
: &Path
) -> io
::Result
<u64> {
10 ErrorKind
::InvalidInput
,
11 "the source path is not an existing regular file",
15 let mut reader
= fs
::File
::open(from
)?
;
16 let mut writer
= fs
::File
::create(to
)?
;
17 let perm
= reader
.metadata()?
.permissions();
19 let ret
= io
::copy(&mut reader
, &mut writer
)?
;
20 fs
::set_permissions(to
, perm
)?
;
24 pub fn remove_dir_all(path
: &Path
) -> io
::Result
<()> {
25 let filetype
= fs
::symlink_metadata(path
)?
.file_type();
26 if filetype
.is_symlink() { fs::remove_file(path) }
else { remove_dir_all_recursive(path) }
29 fn remove_dir_all_recursive(path
: &Path
) -> io
::Result
<()> {
30 for child
in fs
::read_dir(path
)?
{
32 if child
.file_type()?
.is_dir() {
33 remove_dir_all_recursive(&child
.path())?
;
35 fs
::remove_file(&child
.path())?
;