Remove a file or directory. If `recursive` is true, removes directories and their contents.
(&self, path: &str, recursive: bool)
| 267 | /// |
| 268 | /// If `recursive` is true, removes directories and their contents. |
| 269 | fn remove_path(&self, path: &str, recursive: bool) -> Result<(), Self::Error> { |
| 270 | let abs_path = self.resolve_path(path)?; |
| 271 | |
| 272 | if fs::symlink_metadata(&abs_path).is_err() { |
| 273 | return Err(io::Error::new( |
| 274 | io::ErrorKind::NotFound, |
| 275 | format!("Path not found: {}", path), |
| 276 | )); |
| 277 | } |
| 278 | |
| 279 | let metadata = fs::symlink_metadata(&abs_path)?; |
| 280 | if metadata.is_dir() && !metadata.file_type().is_symlink() { |
| 281 | if recursive { |
| 282 | fs::remove_dir_all(&abs_path) |
| 283 | } else { |
| 284 | fs::remove_dir(&abs_path) |
| 285 | } |
| 286 | } else { |
| 287 | fs::remove_file(&abs_path) |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | /// Rename a file or directory. |
| 292 | fn rename(&self, from: &str, to: &str) -> Result<(), Self::Error> { |