From 8f410d1ead74b979481f1488a4dcddd33ea829c7 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Thu, 25 Aug 2022 21:27:39 +1200 Subject: Initial commit --- src/error.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/error.rs (limited to 'src/error.rs') diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..0e8d99f --- /dev/null +++ b/src/error.rs @@ -0,0 +1,48 @@ +use std::io::Error as IoError; +use std::io::ErrorKind; + +#[derive(Debug)] +pub enum EntryReadError { + NotFound, + PermissionDenied, +} +impl From 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 for EntryWriteError { + fn from(error: EntryReadError) -> Self { + match error { + EntryReadError::NotFound => EntryWriteError::NotFound, + EntryReadError::PermissionDenied => EntryWriteError::PermissionDenied, + } + } +} +impl From 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), + } + } +} -- cgit v1.2.3-70-g09d2