Remove a file or directory. If `recursive` is true, removes directories and their contents.
(&self, path: &str, recursive: bool)
| 245 | /// |
| 246 | /// If `recursive` is true, removes directories and their contents. |
| 247 | fn remove_path(&self, path: &str, recursive: bool) -> Result<(), Self::Error> { |
| 248 | let abs_path = self.resolve_path(path)?; |
| 249 | |
| 250 | if !abs_path.exists() { |
| 251 | return Err(io::Error::new( |
| 252 | io::ErrorKind::NotFound, |
| 253 | format!("Path not found: {}", path), |
| 254 | )); |
| 255 | } |
| 256 | |
| 257 | if abs_path.is_dir() { |
| 258 | if recursive { |
| 259 | fs::remove_dir_all(&abs_path) |
| 260 | } else { |
| 261 | fs::remove_dir(&abs_path) |
| 262 | } |
| 263 | } else { |
| 264 | fs::remove_file(&abs_path) |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | /// Rename a file or directory. |
| 269 | fn rename(&self, from: &str, to: &str) -> Result<(), Self::Error> { |