Skip to main content

debian_workspace/
lib.rs

1//! Utilities for reading and writing a Debian package working tree.
2
3#![deny(missing_docs)]
4
5/// Actions that describe changes to apply to a working tree.
6pub mod action;
7
8/// Apply [`action::Action`]s to a working tree.
9pub mod appliers;
10
11/// Operate on a Debian package.
12pub mod workspace;
13
14/// A workspace implementation on a filesystem.
15pub mod fs_workspace;
16
17/// Allow notification on certain events.
18pub mod trigger;
19
20/// Heuristics for classifying binary packages (transitional/meta-package).
21pub mod package_class;
22
23pub use debversion::Version;
24pub use trigger::{ChangelogAspect, Trigger, WatchAspect};
25pub use workspace::{Workspace, compat_level};
26
27/// Errors that can occur while reading or writing workspace files.
28#[derive(Debug)]
29pub enum Error {
30    /// The file is missing; the caller should treat this as "nothing to do".
31    NotFound,
32    /// An I/O error other than file-not-found.
33    Io(std::io::Error),
34    /// The file could not be parsed.
35    Parse(String),
36    /// Any other error.
37    Other(String),
38    /// A required external tool is not installed.
39    MissingDependency(String),
40}
41
42impl std::fmt::Display for Error {
43    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44        match self {
45            Error::NotFound => write!(f, "file not found"),
46            Error::Io(e) => write!(f, "I/O error: {}", e),
47            Error::Parse(msg) => write!(f, "parse error: {}", msg),
48            Error::Other(msg) => write!(f, "{}", msg),
49            Error::MissingDependency(dep) => write!(f, "missing dependency: {}", dep),
50        }
51    }
52}
53
54impl std::error::Error for Error {
55    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
56        match self {
57            Error::Io(e) => Some(e),
58            _ => None,
59        }
60    }
61}
62
63impl From<debian_analyzer::editor::EditorError> for Error {
64    fn from(e: debian_analyzer::editor::EditorError) -> Self {
65        match e {
66            debian_analyzer::editor::EditorError::IoError(e) => Error::Io(e),
67            debian_analyzer::editor::EditorError::BrzError(e) => Error::Other(e.to_string()),
68            debian_analyzer::editor::EditorError::GeneratedFile(p, _) => {
69                Error::Other(format!("generated file: {}", p.display()))
70            }
71            debian_analyzer::editor::EditorError::FormattingUnpreservable(p, _) => {
72                Error::Other(format!("formatting unpreservable: {}", p.display()))
73            }
74            debian_analyzer::editor::EditorError::TemplateError(p, _) => {
75                Error::Other(format!("template error in {}", p.display()))
76            }
77        }
78    }
79}
80
81impl From<std::io::Error> for Error {
82    fn from(e: std::io::Error) -> Self {
83        if e.kind() == std::io::ErrorKind::NotFound {
84            Error::NotFound
85        } else {
86            Error::Io(e)
87        }
88    }
89}