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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use std::fmt::Display;
pub type Result<T> = core::result::Result<T, Error>;
/// General error wrapping more specific errors.
#[derive(Debug)]
pub enum Error {
// Read errors
/// The file had an invalid magic number. Provides the magic number read.
InvalidFileMagic(u32),
/// An record had an invalid magic number. Provides the magic number read.
InvalidRecordMagic(u16),
/// The record was invalid. This also may indicate some unsupported features.
InvalidRecord,
/// The record had an empty file name.
EmptyFilename,
/// The decoding table of the record is invalid.
BadSymbolTable,
/// The decoding table of the record is invalid.
InvalidLevelIndex,
/// The decoding table of the record is invalid.
InvalidTreelevel,
/// File size is bigger than 4 GiB. Actually the lib doesn't support larger files.
FileToBig,
/// A filename was not found in archive
FileNotFound,
/// A record contains unsupported file type
UnsupportedFileType(String),
// Extraction errors
/// File system entry mode could not be set. Typically should contain a `std::io::error`.
#[allow(dead_code)]
ModeError(Box<dyn std::error::Error + Send + Sync>),
/// The record has no parent directory. This should never occur.
MissingParentDir(String),
// Other errors
/// `std::io:error` occured.
IoError(std::io::Error),
}
impl std::error::Error for Error {}
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use Error::*;
match self {
// Read errors
BadSymbolTable => write!(f, "Invalid file format: Bad symbol table."),
EmptyFilename => {
write!(f, "Record having an empty filename will be skipped.")
}
FileToBig => write!(f, "The file size is to big. Has to be max 4 GiB."),
InvalidFileMagic(magic) => write!(
f,
"Invalid file format: File has an invalid magic number '{magic}'."
),
InvalidLevelIndex => {
write!(f, "Invalid file format: Invalid level index found.")
}
InvalidRecordMagic(magic) => write!(
f,
"Invalid file format: Record has an invalid magic number '{magic}'."
),
InvalidRecord => write!(f, "Invalid or unsupported record found."),
InvalidTreelevel => {
write!(f, "Invalid file format: Invalid tree levels.")
}
FileNotFound => write!(f, "Filename wasn't found in archive."),
UnsupportedFileType(s) => write!(f, "The file type of the record is unsupported: {s}."),
// Extraction errors
ModeError(mode_error) => {
write!(f, "Failed to set file modes: {mode_error}")
}
MissingParentDir(path) => write!(f, "Directory is impossible: {path}"),
// Other errors
IoError(io_error) => write!(f, "{io_error}"),
}
}
}
impl From<std::io::Error> for Error {
fn from(value: std::io::Error) -> Self {
Error::IoError(value)
}
}