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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#![warn(missing_docs, rust_2018_idioms)]
pub mod assets;
pub mod config;
pub mod html;
pub mod platform;
#[cfg(feature = "resources")]
pub mod resources;
pub mod pattern;
#[derive(Debug, Clone)]
pub struct PackageInfo {
pub name: String,
pub version: String,
pub authors: &'static str,
pub description: &'static str,
}
impl PackageInfo {
pub fn package_name(&self) -> String {
#[cfg(target_os = "linux")]
{
use heck::ToKebabCase;
self.name.clone().to_kebab_case()
}
#[cfg(not(target_os = "linux"))]
self.name.clone()
}
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct Env {
#[cfg(target_os = "linux")]
pub appimage: Option<std::ffi::OsString>,
#[cfg(target_os = "linux")]
pub appdir: Option<std::ffi::OsString>,
}
#[allow(clippy::derivable_impls)]
impl Default for Env {
fn default() -> Self {
#[cfg(target_os = "linux")]
{
let env = Self {
#[cfg(target_os = "linux")]
appimage: std::env::var_os("APPIMAGE"),
#[cfg(target_os = "linux")]
appdir: std::env::var_os("APPDIR"),
};
if env.appimage.is_some() || env.appdir.is_some() {
let is_temp = std::env::current_exe()
.map(|p| {
p.display()
.to_string()
.starts_with(&format!("{}/.mount_", std::env::temp_dir().display()))
})
.unwrap_or(true);
if !is_temp {
panic!("`APPDIR` or `APPIMAGE` environment variable found but this application was not detected as an AppImage; this might be a security issue.");
}
}
env
}
#[cfg(not(target_os = "linux"))]
{
Self {}
}
}
}
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("Unable to determine target-architecture")]
Architecture,
#[error("Unable to determine target-os")]
Os,
#[error("Unable to determine target-environment")]
Environment,
#[error("Unsupported platform for reading resources")]
UnsupportedPlatform,
#[error("Could not get parent process")]
ParentProcess,
#[error("Could not get parent PID")]
ParentPid,
#[error("Could not get child process")]
ChildProcess,
#[error("{0}")]
Io(#[from] std::io::Error),
#[error("invalid pattern `{0}`. Expected either `brownfield` or `isolation`.")]
InvalidPattern(String),
#[cfg(feature = "resources")]
#[error("{0}")]
GlobPattern(#[from] glob::PatternError),
#[cfg(feature = "resources")]
#[error("`{0}`")]
Glob(#[from] glob::GlobError),
#[cfg(feature = "resources")]
#[error("path matching {0} not found.")]
GlobPathNotFound(String),
#[cfg(feature = "resources")]
#[error("{0}")]
WalkdirError(#[from] walkdir::Error),
#[cfg(feature = "resources")]
#[error("could not walk directory `{0}`, try changing `allow_walk` to true on the `ResourcePaths` constructor.")]
NotAllowedToWalkDir(std::path::PathBuf),
}