1 use std::fs; 2 use std::io; 3 use std::path::Path; 4 remove_file_or_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()>5fn remove_file_or_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> { 6 match fs::remove_file(&path) { 7 // Unfortunately, there is no ErrorKind for EISDIR 8 Err(e) if e.raw_os_error() == Some(libc::EISDIR) => 9 fs::remove_dir_all(&path), 10 r => r, 11 } 12 } 13 _remove_dir_contents<P: AsRef<Path>>(path: P) -> Result<(), io::Error>14pub fn _remove_dir_contents<P: AsRef<Path>>(path: P) -> Result<(), io::Error> { 15 for entry in fs::read_dir(path)? { 16 let entry_path = entry?.path(); 17 remove_file_or_dir_all(&entry_path)?; 18 } 19 20 Ok(()) 21 } 22