Changes the current location. Given that we currently do not support directories, the location can only be of the forms `DRIVE:` or `DRIVE:/`.
(&mut self, location: &str)
| 513 | /// Given that we currently do not support directories, the location can only be of the forms |
| 514 | /// `DRIVE:` or `DRIVE:/`. |
| 515 | pub fn cd(&mut self, location: &str) -> io::Result<()> { |
| 516 | let location = Location::new(location)?; |
| 517 | if location.leaf_name().is_some() { |
| 518 | return Err(io::Error::new(io::ErrorKind::InvalidInput, "Cannot cd to a file")); |
| 519 | } |
| 520 | |
| 521 | match location.drive { |
| 522 | Some(drive) => { |
| 523 | if !self.drives.contains_key(&drive) { |
| 524 | return Err(io::Error::new( |
| 525 | io::ErrorKind::AlreadyExists, |
| 526 | format!("Drive '{}' is not mounted", drive), |
| 527 | )); |
| 528 | } |
| 529 | self.current = drive; |
| 530 | Ok(()) |
| 531 | } |
| 532 | None => Ok(()), |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | /// Returns the current location, used to resolve relative paths. |
| 537 | pub fn cwd(&self) -> String { |