vagabond/src/error.rs

49 lines
1.6 KiB
Rust

use std::io::Error as IoError;
use std::io::ErrorKind;
#[derive(Debug)]
pub enum EntryReadError {
NotFound,
PermissionDenied,
}
impl From<IoError> for EntryReadError {
fn from(io_error: IoError) -> Self {
match io_error.kind() {
ErrorKind::NotFound => Self::NotFound,
// An intermediate path component was a plain file, not a directory
ErrorKind::NotADirectory => Self::NotFound,
// A cyclic symbolic link chain was included in the provided path
ErrorKind::FilesystemLoop => Self::NotFound,
ErrorKind::PermissionDenied => Self::PermissionDenied,
err => panic!("Unexpected IoError encountered: {:?}", err),
}
}
}
#[derive(Debug)]
pub enum EntryWriteError {
NotFound,
PermissionDenied,
}
impl From<EntryReadError> for EntryWriteError {
fn from(error: EntryReadError) -> Self {
match error {
EntryReadError::NotFound => EntryWriteError::NotFound,
EntryReadError::PermissionDenied => EntryWriteError::PermissionDenied,
}
}
}
impl From<IoError> for EntryWriteError {
fn from(io_error: IoError) -> Self {
match io_error.kind() {
ErrorKind::NotFound => Self::NotFound,
// An intermediate path component was a plain file, not a directory
ErrorKind::NotADirectory => Self::NotFound,
// A cyclic symbolic link chain was included in the provided path
ErrorKind::FilesystemLoop => Self::NotFound,
ErrorKind::PermissionDenied => Self::PermissionDenied,
err => panic!("Unexpected IoError encountered: {:?}", err),
}
}
}