1mod bin;
2pub mod ext;
3mod package;
4mod transaction;
5
6pub use bin::*;
7pub use package::*;
8pub use transaction::*;
9
10use std::io;
11use std::path::PathBuf;
12
13use pkgar_core::Entry;
14
15const READ_WRITE_HASH_BUF_SIZE: usize = 4 * 1024 * 1024;
16
17#[derive(Debug, thiserror::Error)]
18pub enum Error {
19 #[error(transparent)]
20 Core(#[from] pkgar_core::Error),
21 #[error(transparent)]
22 Keys(#[from] pkgar_keys::Error),
23 #[error("{source} ({path:?}) {context:?}")]
24 Io {
25 #[source]
26 source: io::Error,
27 path: Option<PathBuf>,
28 context: &'static str,
29 },
30 #[error("Failed to commit transaction ({changed} files changed, {remaining} files remaining): {source}")]
31 FailedCommit {
32 #[source]
33 source: Box<Self>,
34 changed: usize,
35 remaining: usize,
36 },
37 #[error("Invalid component '{}' in path '{}'{}", invalid.display(), path.display(), entry.as_ref().map(|_| " while parsing entry").unwrap_or_default())]
38 InvalidPathComponent {
39 invalid: PathBuf,
40 path: PathBuf,
41 entry: Option<Box<Entry>>,
42 },
43 #[error("Entry size mismatch: expected {expected}; got {actual}")]
44 LengthMismatch { actual: u64, expected: u64 },
45 #[error("Data not initialized.")]
46 DataNotInitialized,
47}
48
49macro_rules! wrap_io_err {
50 ($context:expr) => {
51 |source| Error::Io {
52 source,
53 path: None,
54 context: $context,
55 }
56 };
57 ($path:expr, $context:expr) => {
58 |source| Error::Io {
59 source,
60 path: Some($path.to_path_buf()),
61 context: $context,
62 }
63 };
64}
65
66pub(crate) use wrap_io_err;