summaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs48
1 files changed, 48 insertions, 0 deletions
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<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),
+ }
+ }
+}