diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2022-08-25 21:27:39 +1200 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2022-08-25 21:27:39 +1200 |
commit | 8f410d1ead74b979481f1488a4dcddd33ea829c7 (patch) | |
tree | 2f22fd930c8d0cdb4de53fef473f7770073e14d5 /src/error.rs | |
download | vagabond-1.0.zip |
Initial commitv1.0
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 48 |
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), + } + } +} |