summaryrefslogtreecommitdiff
path: root/src/error.rs
blob: 0e8d99fdb18d01c0e4786ad4bb4ed3dfc779e262 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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),
        }
    }
}