diff --git a/.rustfmt.toml b/.rustfmt.toml
new file mode 100644
index 0000000..209b16b
--- /dev/null
+++ b/.rustfmt.toml
@@ -0,0 +1,16 @@
+unstable_features = true
+indent_style = "Block"
+imports_indent = "Block"
+imports_layout = "HorizontalVertical"
+imports_granularity = "Crate"
+brace_style = "PreferSameLine"
+match_arm_leading_pipes = "Never"
+match_arm_blocks = false
+condense_wildcard_suffixes = true
+overflow_delimited_expr = false
+spaces_around_ranges = true
+reorder_imports = true
+hard_tabs = false
+max_width = 130
+fn_call_width = 120
+chain_width = 90
diff --git a/bin/pacwrap-utils b/bin/pacwrap-utils
index 5a39811..1349aeb 100755
--- a/bin/pacwrap-utils
+++ b/bin/pacwrap-utils
@@ -355,7 +355,7 @@ replicate_instance() {
[[ $type != BASE ]] && depend=$(return_dependency)
case $type in
- ROOT) params+="r";;
+ ROOT) params+="a";;
BASE) params+="b";;
DEP) params+="s";;
LINK) ln -s "$INSTANCE_ROOT_DIR/$depend" "$INSTANCE_ROOT_DIR/$instance"
diff --git a/dist/tools/clean.sh b/dist/tools/clean.sh
index 92b31cc..d35f751 100755
--- a/dist/tools/clean.sh
+++ b/dist/tools/clean.sh
@@ -18,10 +18,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
-BOLD=$(tput bold)
-GREEN=$(tput setaf 2)
-RED=$(tput setaf 1)
-RESET=$(tput sgr0)
+if ! [[ -z $COLORTERM ]] || [[ $TERM == "dummy" ]]; then
+ BOLD=$(tput bold)
+ GREEN=$(tput setaf 2)
+ RED=$(tput setaf 1)
+ RESET=$(tput sgr0)
+fi
+
DIST_RUNTIME="./dist/runtime"
DIST_BASE="./dist/pacwrap-base-dist"
DIST_REPO="./dist/repo"
diff --git a/dist/tools/runtime.sh b/dist/tools/runtime.sh
index 8bf1f63..8fe1601 100755
--- a/dist/tools/runtime.sh
+++ b/dist/tools/runtime.sh
@@ -21,10 +21,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
-BOLD=$(tput bold)
-RED=$(tput setaf 1)
-GREEN=$(tput setaf 2)
-RESET=$(tput sgr0)
+if ! [[ -z $COLORTERM ]] || [[ $TERM == "dummy" ]]; then
+ BOLD=$(tput bold)
+ RED=$(tput setaf 1)
+ GREEN=$(tput setaf 2)
+ RESET=$(tput sgr0)
+fi
+
LIB_DIR="/lib"
BIN_DIR="/bin"
DEST_DIR="./dist/runtime"
diff --git a/pacwrap-agent/build.rs b/pacwrap-agent/build.rs
index 67592c3..cea9ee9 100644
--- a/pacwrap-agent/build.rs
+++ b/pacwrap-agent/build.rs
@@ -1,6 +1,6 @@
/*
* pacwrap-agent
- *
+ *
* Copyright (C) 2023-2024 Xavier R.M.
* SPDX-License-Identifier: GPL-3.0-only
*
@@ -18,7 +18,7 @@
*/
fn main() {
- if ! cfg!(target_os="linux") || ! cfg!(target_family="unix") {
+ if !cfg!(target_os = "linux") || !cfg!(target_family = "unix") {
panic!("Unsupported build target. Please refer to the documentation for further information.")
}
}
diff --git a/pacwrap-agent/src/agent.rs b/pacwrap-agent/src/agent.rs
index ec1d106..b620eee 100644
--- a/pacwrap-agent/src/agent.rs
+++ b/pacwrap-agent/src/agent.rs
@@ -1,6 +1,6 @@
/*
* pacwrap-agent
- *
+ *
* Copyright (C) 2023-2024 Xavier R.M.
* SPDX-License-Identifier: GPL-3.0-only
*
@@ -16,57 +16,64 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-use std::{fs::{self, File}, io::ErrorKind::NotFound, os::unix::prelude::FileExt, env};
+use std::{
+ env,
+ fs::{self, File},
+ io::ErrorKind::NotFound,
+ os::unix::prelude::FileExt,
+};
use serde::Deserialize;
-use pacwrap_core::{err,
+use pacwrap_core::{
+ config::Global,
+ err,
+ sync::{
+ self,
+ event::{
+ download::{self, DownloadEvent},
+ progress::{self, ProgressEvent},
+ query,
+ },
+ transaction::{TransactionHandle, TransactionMetadata, TransactionParameters, TransactionType, MAGIC_NUMBER},
+ utils::{erroneous_preparation, erroneous_transaction},
+ AlpmConfigData,
+ SyncError,
+ },
+ utils::{print_warning, read_le_32},
Error,
Result,
- sync::{self,
- SyncError,
- AlpmConfigData,
- utils::{erroneous_transaction,
- erroneous_preparation},
- transaction::{TransactionHandle,
- TransactionType,
- TransactionMetadata,
- TransactionParameters,
- MAGIC_NUMBER},
- event::{download::{self, DownloadEvent},
- progress::{self, ProgressEvent},
- query}},
- utils::{print_warning, read_le_32}, config::Global};
+};
use crate::error::AgentError;
static AGENT_PARAMS: &'static str = "/mnt/agent_params";
pub fn transact() -> Result<()> {
- let mut header_buffer = vec![0; 7];
+ let mut header_buffer = vec![0; 7];
let mut file = match File::open(AGENT_PARAMS) {
Ok(file) => file,
Err(error) => {
if let Ok(var) = env::var("SHELL") {
- if ! var.is_empty() {
+ if !var.is_empty() {
err!(AgentError::DirectExecution)?
}
}
err!(AgentError::IOError(AGENT_PARAMS, error.kind()))?
- },
- };
+ }
+ };
if let Err(error) = file.read_exact_at(&mut header_buffer, 0) {
err!(AgentError::IOError(AGENT_PARAMS, error.kind()))?
}
-
+
decode_header(&header_buffer)?;
let params: TransactionParameters = deserialize(&mut file)?;
let config: Global = deserialize(&mut file)?;
let alpm_remotes: AlpmConfigData = deserialize(&mut file)?;
- let mut metadata: TransactionMetadata = deserialize(&mut file)?;
+ let mut metadata: TransactionMetadata = deserialize(&mut file)?;
let alpm = sync::instantiate_alpm_agent(&config, &alpm_remotes);
let mut handle = TransactionHandle::new(&config, alpm, &mut metadata);
@@ -74,11 +81,11 @@ pub fn transact() -> Result<()> {
}
fn conduct_transaction(config: &Global, handle: &mut TransactionHandle, agent: TransactionParameters) -> Result<()> {
- let flags = handle.retrieve_flags();
+ let flags = handle.retrieve_flags();
let mode = agent.mode();
let action = agent.action();
let config = config.config();
- let progress = config.progress();
+ let pkind = config.progress();
let bytes = agent.bytes();
let files = agent.files();
@@ -86,12 +93,12 @@ fn conduct_transaction(config: &Global, handle: &mut TransactionHandle, agent: T
err!(SyncError::InitializationFailure(error.to_string().into()))?
}
- handle.ignore(true);
+ handle.ignore(true);
- if let TransactionType::Upgrade(upgrade, downgrade, _) = action {
+ if let TransactionType::Upgrade(upgrade, downgrade, _) = action {
if upgrade {
handle.alpm().sync_sysupgrade(downgrade).unwrap();
- }
+ }
}
handle.prepare(&action, &flags.0.unwrap())?;
@@ -100,17 +107,12 @@ fn conduct_transaction(config: &Global, handle: &mut TransactionHandle, agent: T
erroneous_preparation(error)?
}
- let progress_cb = ProgressEvent::new()
- .style(progress.0)
- .configure(&action);
- let download_cb = DownloadEvent::new()
- .style(progress.0)
- .total(bytes, files)
- .configure(&mode, progress.1);
+ let progress_cb = ProgressEvent::new().style(pkind.0).configure(&action);
+ let download_cb = DownloadEvent::new().style(pkind.0).total(bytes, files).configure(&mode, pkind.1);
handle.alpm().set_question_cb((), query::callback);
- handle.alpm().set_progress_cb(progress_cb, progress::callback(&mode, progress.0));
- handle.alpm().set_dl_cb(download_cb, download::callback(progress.1));
+ handle.alpm().set_progress_cb(progress_cb, progress::callback(&mode, pkind.0));
+ handle.alpm().set_dl_cb(download_cb, download::callback(pkind.1));
if let Err(error) = handle.alpm_mut().trans_commit() {
erroneous_transaction(error)?
@@ -121,7 +123,8 @@ fn conduct_transaction(config: &Global, handle: &mut TransactionHandle, agent: T
if let Err(error) = fs::copy("/etc/ld.so.cache", "/mnt/fs/etc/ld.so.cache") {
match error.kind() {
- NotFound => (), _ => print_warning(format!("Failed to propagate ld.so.cache: {}", error)),
+ NotFound => (),
+ _ => print_warning(format!("Failed to propagate ld.so.cache: {}", error)),
}
}
@@ -139,7 +142,7 @@ fn decode_header(buffer: &Vec) -> Result<()> {
}
if major.0 != major.1 || minor.0 != minor.1 || patch.0 != patch.1 {
- err!(AgentError::InvalidVersion(major.0,minor.0,patch.0,major.1,minor.1,patch.1))?;
+ err!(AgentError::InvalidVersion(major.0, minor.0, patch.0, major.1, minor.1, patch.1))?;
}
Ok(())
@@ -148,6 +151,6 @@ fn decode_header(buffer: &Vec) -> Result<()> {
fn deserialize Deserialize<'de>>(stdin: &mut File) -> Result {
match bincode::deserialize_from::<&mut File, T>(stdin) {
Ok(meta) => Ok(meta),
- Err(error) => err!(AgentError::DeserializationError(error.as_ref().to_string()))
+ Err(error) => err!(AgentError::DeserializationError(error.as_ref().to_string())),
}
}
diff --git a/pacwrap-agent/src/error.rs b/pacwrap-agent/src/error.rs
index 2db3e17..7811d68 100644
--- a/pacwrap-agent/src/error.rs
+++ b/pacwrap-agent/src/error.rs
@@ -1,6 +1,6 @@
/*
* pacwrap-agent
- *
+ *
* Copyright (C) 2023-2024 Xavier R.M.
* SPDX-License-Identifier: GPL-3.0-only
*
@@ -19,25 +19,30 @@
use std::fmt::{Display, Formatter};
-use pacwrap_core::{ErrorTrait, constants::{RESET, BOLD}};
+use pacwrap_core::{
+ constants::{BOLD, RESET},
+ ErrorTrait,
+};
#[derive(Debug)]
pub enum AgentError {
DeserializationError(String),
- InvalidVersion(u8,u8,u8,u8,u8,u8),
+ InvalidVersion(u8, u8, u8, u8, u8, u8),
InvalidMagic(u32, u32),
IOError(&'static str, std::io::ErrorKind),
DirectExecution,
}
impl Display for AgentError {
- fn fmt(&self, fmter: &mut Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
+ fn fmt(&self, fmter: &mut Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
match self {
Self::DirectExecution => write!(fmter, "Direct execution of this binary is unsupported."),
Self::InvalidMagic(magic, comparator) => write!(fmter, "Magic mismatch {} != {}", magic, comparator),
- Self::InvalidVersion(a, b, c, d, e, f) => write!(fmter, "Version mismatch {}.{}.{} != {}.{}.{}", a, b, c, d, e, f),
+ Self::InvalidVersion(a, b, c, d, e, f) => {
+ write!(fmter, "Version mismatch {}.{}.{} != {}.{}.{}", a, b, c, d, e, f)
+ }
Self::DeserializationError(error) => write!(fmter, "Deserilization error: {}", error),
- Self::IOError(file, error) => write!(fmter, "'{}{}{}' {}", *BOLD, file, *RESET, error)
+ Self::IOError(file, error) => write!(fmter, "'{}{}{}' {}", *BOLD, file, *RESET, error),
}
}
}
@@ -49,7 +54,7 @@ impl ErrorTrait for AgentError {
Self::InvalidVersion(..) => 4,
Self::DeserializationError(..) => 3,
Self::IOError(..) => 2,
- _ => 1
+ _ => 1,
}
- }
+ }
}
diff --git a/pacwrap-agent/src/main.rs b/pacwrap-agent/src/main.rs
index 458d9cd..1c9e33f 100644
--- a/pacwrap-agent/src/main.rs
+++ b/pacwrap-agent/src/main.rs
@@ -1,6 +1,6 @@
/*
* pacwrap-agent
- *
+ *
* Copyright (C) 2023-2024 Xavier R.M.
* SPDX-License-Identifier: GPL-3.0-only
*
@@ -17,20 +17,25 @@
* along with this program. If not, see .
*/
-use pacwrap_core::{err, Error, utils::{Arguments, arguments::Operand}};
+use pacwrap_core::{
+ err,
+ utils::{arguments::Operand, Arguments},
+ Error,
+};
use crate::error::AgentError;
-mod error;
mod agent;
+mod error;
fn main() {
let arguments = &mut Arguments::new().populate();
let param = arguments.next().unwrap_or_default();
let result = match param {
- Operand::Value("transact") => agent::transact(), _ => err!(AgentError::DirectExecution)
+ Operand::Value("transact") => agent::transact(),
+ _ => err!(AgentError::DirectExecution),
};
-
+
if let Err(error) = result {
error.handle();
}
diff --git a/pacwrap-core/build.rs b/pacwrap-core/build.rs
index 18685fb..cd5563f 100644
--- a/pacwrap-core/build.rs
+++ b/pacwrap-core/build.rs
@@ -1,6 +1,6 @@
/*
* pacwrap-core
- *
+ *
* Copyright (C) 2023-2024 Xavier R.M.
* SPDX-License-Identifier: GPL-3.0-only
*
@@ -27,7 +27,7 @@ fn dist_repo() -> String {
}
fn main() {
- if ! cfg!(target_os="linux") || ! cfg!(target_family="unix") {
+ if !cfg!(target_os = "linux") || !cfg!(target_family = "unix") {
panic!("Unsupported build target. Please refer to the documentation for further information.")
}
diff --git a/pacwrap-core/src/config.rs b/pacwrap-core/src/config.rs
index 9b2cdae..cd4c1f1 100644
--- a/pacwrap-core/src/config.rs
+++ b/pacwrap-core/src/config.rs
@@ -1,6 +1,6 @@
/*
* pacwrap-core
- *
+ *
* Copyright (C) 2023-2024 Xavier R.M.
* SPDX-License-Identifier: GPL-3.0-only
*
@@ -17,35 +17,42 @@
* along with this program. If not, see .
*/
-use std::{fmt::Display,
- io::{Write, ErrorKind::NotFound},
- fmt::Formatter,
- path::Path,
- fs::File};
+use std::{
+ fmt::{Display, Formatter},
+ fs::File,
+ io::{ErrorKind::NotFound, Write},
+ path::Path,
+};
use serde::Serialize;
-use crate::{err, impl_error, ErrorKind, error::*, constants::{BOLD, RESET, CONFIG_FILE}};
+use crate::{
+ constants::{BOLD, CONFIG_FILE, RESET},
+ err,
+ error::*,
+ impl_error,
+ ErrorKind,
+};
-pub use self::{cache::InstanceCache,
- instance::{Instance,
- InstanceHandle,
- InstanceType},
- vars::InsVars,
- filesystem::{Filesystem, BindError},
- permission::{Permission, PermError},
+pub use self::{
+ cache::InstanceCache,
dbus::Dbus,
- global::{Global, CONFIG}};
+ filesystem::{BindError, Filesystem},
+ global::{Global, CONFIG},
+ instance::{Instance, InstanceHandle, InstanceType},
+ permission::{PermError, Permission},
+ vars::InsVars,
+};
-pub mod vars;
-pub mod filesystem;
-pub mod permission;
-pub mod dbus;
pub mod cache;
-pub mod instance;
-pub mod init;
-pub mod register;
+pub mod dbus;
+pub mod filesystem;
pub mod global;
+pub mod init;
+pub mod instance;
+pub mod permission;
+pub mod register;
+pub mod vars;
#[derive(Debug, Clone)]
pub enum ConfigError {
@@ -61,13 +68,13 @@ impl_error!(ConfigError);
impl Display for ConfigError {
fn fmt(&self, fmter: &mut Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
- match self {
- Self::Filesystem(module, err) => write!(fmter, "Failed to register filesystem {}: {} ", module, err),
- Self::Permission(module, err) => write!(fmter, "Failed to register permission {}: {} ", module, err),
+ match self {
+ Self::Filesystem(module, err) => write!(fmter, "Failed to register filesystem '{}': {} ", module, err),
+ Self::Permission(module, err) => write!(fmter, "Failed to register permission '{}': {} ", module, err),
Self::Load(ins, error) => write!(fmter, "Failed to load '{ins}': {error}"),
Self::Save(ins, error) => write!(fmter, "Failed to save '{ins}': {error}"),
Self::AlreadyExists(ins) => write!(fmter, "Container {}{ins}{} already exists.", *BOLD, *RESET),
- Self::ConfigNotFound(ins) => write!(fmter, "Configuration '{}{ins}{}.yml' not found.", *BOLD, *RESET)
+ Self::ConfigNotFound(ins) => write!(fmter, "Configuration '{}{ins}{}' not found.", *BOLD, *RESET),
}
}
}
@@ -79,10 +86,10 @@ impl From for String {
}
#[inline]
-pub fn provide_handle(instance: &str) -> Result {
+pub fn provide_handle(instance: &str) -> Result {
let vars = InsVars::new(instance);
- if ! Path::new(vars.root()).exists() {
+ if !Path::new(vars.root()).exists() {
err!(ErrorKind::InstanceNotFound(instance.into()))?
}
@@ -94,19 +101,19 @@ pub fn provide_new_handle(instance: &str) -> Result {
handle(instance, InsVars::new(instance))
}
-fn save(obj: &T, path: &str) -> Result<()> {
+fn save(obj: &T, path: &str) -> Result<()> {
let mut f = match File::create(Path::new(path)) {
Ok(f) => f,
- Err(error) => err!(ErrorKind::IOError(path.into(), error.kind()))?
+ Err(error) => err!(ErrorKind::IOError(path.into(), error.kind()))?,
};
let config = match serde_yaml::to_string(&obj) {
Ok(file) => file,
- Err(error) => err!(ConfigError::Save(path.into(), error.to_string()))?
+ Err(error) => err!(ConfigError::Save(path.into(), error.to_string()))?,
};
-
+
match write!(f, "{}", config) {
Ok(_) => Ok(()),
- Err(error) => err!(ErrorKind::IOError(path.into(), error.kind()))
+ Err(error) => err!(ErrorKind::IOError(path.into(), error.kind())),
}
}
@@ -115,15 +122,15 @@ fn handle<'a>(instance: &str, vars: InsVars<'a>) -> Result> {
Ok(file) => {
let config = match serde_yaml::from_reader(&file) {
Ok(file) => file,
- Err(error) => err!(ConfigError::Load(vars.instance().into(), error.to_string()))?
+ Err(error) => err!(ConfigError::Load(vars.instance().into(), error.to_string()))?,
};
Ok(InstanceHandle::new(config, vars))
- },
+ }
Err(error) => match error.kind() {
NotFound => err!(ConfigError::ConfigNotFound(instance.into()))?,
_ => err!(ErrorKind::IOError(vars.config_path().into(), error.kind()))?,
- }
+ },
}
}
@@ -133,11 +140,11 @@ fn config() -> Result {
match File::open(*CONFIG_FILE) {
Ok(file) => match serde_yaml::from_reader(&file) {
Ok(file) => Ok(file),
- Err(error) => err!(ConfigError::Load(CONFIG_FILE.to_string(), error.to_string()))?
+ Err(error) => err!(ConfigError::Load(CONFIG_FILE.to_string(), error.to_string()))?,
},
Err(error) => match error.kind() {
NotFound => err!(ConfigError::ConfigNotFound(CONFIG_FILE.to_string()))?,
_ => err!(ErrorKind::IOError(CONFIG_FILE.to_string(), error.kind()))?,
- }
+ },
}
}
diff --git a/pacwrap-core/src/config/cache.rs b/pacwrap-core/src/config/cache.rs
index ef87993..021ba47 100644
--- a/pacwrap-core/src/config/cache.rs
+++ b/pacwrap-core/src/config/cache.rs
@@ -1,6 +1,6 @@
/*
* pacwrap-core
- *
+ *
* Copyright (C) 2023-2024 Xavier R.M.
* SPDX-License-Identifier: GPL-3.0-only
*
@@ -19,33 +19,24 @@
use std::{collections::HashMap, fs::read_dir};
-use crate::{err,
- ErrorKind,
+use crate::{
+ config::{self, InstanceHandle},
+ constants::DATA_DIR,
+ err,
error::*,
- constants::DATA_DIR,
- config::{self, InstanceHandle}};
+ ErrorKind,
+};
-use super::{InsVars,
- ConfigError,
- Instance,
- instance::InstanceType};
+use super::{instance::InstanceType, ConfigError, InsVars, Instance};
pub struct InstanceCache<'a> {
instances: HashMap<&'a str, InstanceHandle<'a>>,
- registered: Vec<&'a str>,
- registered_base: Vec<&'a str>,
- registered_dep: Vec<&'a str>,
- registered_root: Vec<&'a str>
}
-impl <'a>InstanceCache<'a> {
+impl<'a> InstanceCache<'a> {
pub fn new() -> Self {
Self {
instances: HashMap::new(),
- registered: Vec::new(),
- registered_base: Vec::new(),
- registered_dep: Vec::new(),
- registered_root: Vec::new(),
}
}
@@ -57,87 +48,84 @@ impl <'a>InstanceCache<'a> {
for dep in deps.iter() {
if let None = self.instances.get(dep) {
err!(ErrorKind::DependencyNotFound((*dep).into(), ins.into()))?
- }
+ }
}
let deps = deps.iter().map(|a| (*a).into()).collect();
let handle = match config::provide_new_handle(ins) {
- Ok(mut handle) => {
- handle.metadata_mut().set(deps, vec!());
- handle
- },
+ Ok(mut handle) => {
+ handle.metadata_mut().set(deps, vec![]);
+ handle
+ }
Err(err) => match err.downcast::() {
Ok(error) => match error {
ConfigError::ConfigNotFound(_) => {
- let vars = InsVars::new(ins);
- let cfg = Instance::new(instype, deps, vec!());
-
- InstanceHandle::new(cfg, vars)
- },
+ let vars = InsVars::new(ins);
+ let cfg = Instance::new(instype, deps, vec![]);
+
+ InstanceHandle::new(cfg, vars)
+ }
_ => Err(err)?,
- }
+ },
_ => Err(err)?,
},
};
- Ok(self.register(ins, handle))
+ Ok(self.register(ins, handle))
}
- fn map(&mut self, ins: &'a str) -> Result<()> {
+ fn map(&mut self, ins: &'a str) -> Result<()> {
if let Some(_) = self.instances.get(ins) {
err!(ConfigError::AlreadyExists(ins.to_owned()))?
}
- Ok(self.register(ins, match config::provide_handle(ins) {
- Ok(ins) => ins,
- Err(error) => {
- error.warn();
- return Ok(())
- }
- }))
+ Ok(self.register(
+ ins,
+ match config::provide_handle(ins) {
+ Ok(ins) => ins,
+ Err(error) => {
+ error.warn();
+ return Ok(());
+ }
+ },
+ ))
}
fn register(&mut self, ins: &'a str, handle: InstanceHandle<'a>) {
- match handle.metadata().container_type() {
- InstanceType::BASE => self.registered_base.push(ins),
- InstanceType::DEP => self.registered_dep.push(ins),
- InstanceType::ROOT => self.registered_root.push(ins),
- InstanceType::LINK => return,
- }
+ if let InstanceType::Symbolic = handle.metadata().container_type() {
+ return;
+ }
self.instances.insert(ins, handle);
- self.registered.push(ins);
}
- pub fn registered(&self) -> &Vec<&'a str> {
- &self.registered
- }
-
- pub fn registered_base(&self) -> &Vec<&'a str> {
- &self.registered_base
- }
-
- pub fn registered_dep(&self) -> &Vec<&'a str> {
- &self.registered_dep
+ pub fn registered(&self) -> Vec<&'a str> {
+ self.instances.iter().map(|a| *a.0).collect()
}
- pub fn registered_root(&self) -> &Vec<&'a str> {
- &self.registered_root
+ pub fn filter(&self, filter: Vec) -> Vec<&'a str> {
+ self.instances
+ .iter()
+ .filter(|a| filter.contains(a.1.metadata().container_type()))
+ .map(|a| *a.0)
+ .collect()
}
pub fn obtain_base_handle(&self) -> Option<&InstanceHandle> {
- match self.registered_base.get(0) {
- Some(instance) => self.instances.get(instance), None => None,
+ match self.filter(vec![InstanceType::Base]).get(0) {
+ Some(instance) => self.instances.get(instance),
+ None => None,
}
}
- pub fn get_instance(&self, ins: &str) -> Result<&InstanceHandle> {
+ pub fn get_instance(&self, ins: &str) -> Result<&InstanceHandle> {
match self.instances.get(ins) {
- Some(ins) => Ok(ins), None => err!(ErrorKind::InstanceNotFound(ins.into())),
+ Some(ins) => Ok(ins),
+ None => err!(ErrorKind::InstanceNotFound(ins.into())),
}
}
- pub fn get_instance_option(&self, ins: &str) -> Option<&InstanceHandle> {
+ pub fn get_instance_option(&self, ins: &str) -> Option<&InstanceHandle> {
self.instances.get(ins)
}
}
@@ -156,22 +144,25 @@ pub fn populate<'a>() -> Result> {
populate_from(&roots()?)
}
-fn roots<'a>() -> Result> {
+fn roots<'a>() -> Result> {
match read_dir(format!("{}/root", *DATA_DIR)) {
- Ok(dir) => Ok(dir.filter(|f| match f {
- Ok(f) => match f.metadata() {
- Ok(meta) => meta.is_dir() | meta.is_symlink(), Err(_) => false
- },
- Err(_) => false
- })
- .map(|s| match s {
+ Ok(dir) => Ok(dir
+ .filter(|f| match f {
+ Ok(f) => match f.metadata() {
+ Ok(meta) => meta.is_dir() | meta.is_symlink(),
+ Err(_) => false,
+ },
+ Err(_) => false,
+ })
+ .map(|s| match s {
Ok(f) => match f.file_name().to_str() {
- Some(f) => f.to_owned().leak(), None => "",
+ Some(f) => f.to_owned().leak(),
+ None => "",
},
Err(_) => "",
})
- .filter(|e| ! e.is_empty())
- .collect()),
+ .filter(|e| !e.is_empty())
+ .collect()),
Err(error) => err!(ErrorKind::IOError(format!("{}/root", *DATA_DIR), error.kind())),
}
}
diff --git a/pacwrap-core/src/config/dbus.rs b/pacwrap-core/src/config/dbus.rs
index 8852c51..9525005 100644
--- a/pacwrap-core/src/config/dbus.rs
+++ b/pacwrap-core/src/config/dbus.rs
@@ -1,6 +1,6 @@
/*
* pacwrap-core
- *
+ *
* Copyright (C) 2023-2024 Xavier R.M.
* SPDX-License-Identifier: GPL-3.0-only
*
@@ -19,13 +19,13 @@
use crate::exec::args::ExecutionArgs;
-use dyn_clone::{DynClone, clone_trait_object};
+use dyn_clone::{clone_trait_object, DynClone};
-mod socket;
mod appindicator;
+mod socket;
mod xdg_portal;
-#[typetag::serde(tag = "permission")]
+#[typetag::serde(tag = "module")]
pub trait Dbus: DynClone {
fn register(&self, args: &mut ExecutionArgs);
}
diff --git a/pacwrap-core/src/config/dbus/appindicator.rs b/pacwrap-core/src/config/dbus/appindicator.rs
index 53086ba..ead0805 100644
--- a/pacwrap-core/src/config/dbus/appindicator.rs
+++ b/pacwrap-core/src/config/dbus/appindicator.rs
@@ -3,10 +3,10 @@ use serde::{Deserialize, Serialize};
use crate::{config::Dbus, exec::args::ExecutionArgs};
#[derive(Debug, Clone, Serialize, Deserialize)]
-struct APPINDICATOR;
+struct AppIndicator;
-#[typetag::serde]
-impl Dbus for APPINDICATOR {
+#[typetag::serde(name = "appindicator")]
+impl Dbus for AppIndicator {
fn register(&self, args: &mut ExecutionArgs) {
args.dbus("broadcast", "org.kde.StatusNotifierWatcher=@/StatusNotifierWatcher");
}
diff --git a/pacwrap-core/src/config/dbus/socket.rs b/pacwrap-core/src/config/dbus/socket.rs
index 98cd6d8..c612155 100644
--- a/pacwrap-core/src/config/dbus/socket.rs
+++ b/pacwrap-core/src/config/dbus/socket.rs
@@ -3,22 +3,20 @@ use serde::{Deserialize, Serialize};
use crate::{config::Dbus, exec::args::ExecutionArgs};
#[derive(Debug, Clone, Serialize, Deserialize)]
-struct SOCKET {
+struct Socket {
socket: String,
- address: Vec
+ address: Vec,
}
-#[typetag::serde]
-impl Dbus for SOCKET {
+#[typetag::serde(name = "socket")]
+impl Dbus for Socket {
fn register(&self, args: &mut ExecutionArgs) {
match self.socket.to_lowercase().as_str() {
- p if p == "call" || p == "talk" || p == "see" || p == "own" || p == "broadcast" => {
+ p if p == "call" || p == "talk" || p == "see" || p == "own" || p == "broadcast" =>
for sock in self.address.iter() {
args.dbus(p, sock);
- }
- },
+ },
&_ => {}
}
}
}
-
diff --git a/pacwrap-core/src/config/dbus/xdg_portal.rs b/pacwrap-core/src/config/dbus/xdg_portal.rs
index 0e5b4e4..b1c70bc 100644
--- a/pacwrap-core/src/config/dbus/xdg_portal.rs
+++ b/pacwrap-core/src/config/dbus/xdg_portal.rs
@@ -5,11 +5,11 @@ use serde::{Deserialize, Serialize};
use crate::{config::Dbus, exec::args::ExecutionArgs};
#[derive(Debug, Clone, Serialize, Deserialize)]
-struct XDG_PORTAL;
+struct XdgPortal;
-#[typetag::serde]
-impl Dbus for XDG_PORTAL {
- fn register(&self, args: &mut ExecutionArgs) {
+#[typetag::serde(name = "xdg_portal")]
+impl Dbus for XdgPortal {
+ fn register(&self, args: &mut ExecutionArgs) {
args.dbus("call", "org.freedesktop.portal.*=*");
args.dbus("broadcast", "org.freedesktop.portal.*=@/org/freedesktop/portal/*");
}
diff --git a/pacwrap-core/src/config/filesystem.rs b/pacwrap-core/src/config/filesystem.rs
index f6dc286..6e224a4 100644
--- a/pacwrap-core/src/config/filesystem.rs
+++ b/pacwrap-core/src/config/filesystem.rs
@@ -1,6 +1,6 @@
/*
* pacwrap-core
- *
+ *
* Copyright (C) 2023-2024 Xavier R.M.
* SPDX-License-Identifier: GPL-3.0-only
*
@@ -19,22 +19,21 @@
use std::fmt::{Display, Formatter};
-use crate::exec::args::ExecutionArgs;
-use crate::config::InsVars;
+use crate::{config::InsVars, exec::args::ExecutionArgs};
-use dyn_clone::{DynClone, clone_trait_object};
+use dyn_clone::{clone_trait_object, DynClone};
+mod dir;
pub mod home;
pub mod root;
+mod sys;
mod to_home;
mod to_root;
-mod dir;
-mod sys;
pub enum Condition {
Success,
SuccessWarn(String),
- Nothing
+ Nothing,
}
#[derive(Debug, Clone)]
@@ -48,7 +47,6 @@ impl Display for BindError {
match self {
Self::Fail(error) => write!(fmter, "{}", error),
Self::Warn(error) => write!(fmter, "{}", error),
-
}
}
}
diff --git a/pacwrap-core/src/config/filesystem/dir.rs b/pacwrap-core/src/config/filesystem/dir.rs
index 5d1f797..08d6e6b 100644
--- a/pacwrap-core/src/config/filesystem/dir.rs
+++ b/pacwrap-core/src/config/filesystem/dir.rs
@@ -1,6 +1,6 @@
/*
* pacwrap-core
- *
+ *
* Copyright (C) 2023-2024 Xavier R.M.
* SPDX-License-Identifier: GPL-3.0-only
*
@@ -19,23 +19,27 @@
use serde::{Deserialize, Serialize};
-use crate::{exec::args::ExecutionArgs,
- config::InsVars,
- config::filesystem::{Filesystem, BindError}};
+use crate::{
+ config::{
+ filesystem::{BindError, Filesystem},
+ InsVars,
+ },
+ exec::args::ExecutionArgs,
+};
#[derive(Debug, Clone, Serialize, Deserialize)]
-pub struct DIR {
+pub struct Dir {
#[serde(default)]
- path: Vec
+ path: Vec,
}
-#[typetag::serde]
-impl Filesystem for DIR {
+#[typetag::serde(name = "dir")]
+impl Filesystem for Dir {
fn check(&self, _vars: &InsVars) -> Result<(), BindError> {
if self.path.len() == 0 {
Err(BindError::Fail(format!("Path not specified.")))?
}
-
+
Ok(())
}
@@ -46,6 +50,6 @@ impl Filesystem for DIR {
}
fn module(&self) -> &'static str {
- "DIR"
+ "dir"
}
}
diff --git a/pacwrap-core/src/config/filesystem/home.rs b/pacwrap-core/src/config/filesystem/home.rs
index 4f3bf3a..0b27c7d 100644
--- a/pacwrap-core/src/config/filesystem/home.rs
+++ b/pacwrap-core/src/config/filesystem/home.rs
@@ -1,6 +1,6 @@
/*
* pacwrap-core
- *
+ *
* Copyright (C) 2023-2024 Xavier R.M.
* SPDX-License-Identifier: GPL-3.0-only
*
@@ -21,18 +21,22 @@ use std::path::Path;
use serde::{Deserialize, Serialize};
-use crate::{exec::args::ExecutionArgs,
- config::InsVars,
- config::filesystem::{Filesystem, BindError}};
+use crate::{
+ config::{
+ filesystem::{BindError, Filesystem},
+ InsVars,
+ },
+ exec::args::ExecutionArgs,
+};
#[derive(Debug, Clone, Serialize, Deserialize)]
-pub struct HOME;
+pub struct Home;
-#[typetag::serde]
-impl Filesystem for HOME {
+#[typetag::serde(name = "home")]
+impl Filesystem for Home {
fn check(&self, vars: &InsVars) -> Result<(), BindError> {
- if ! Path::new(vars.home()).exists() {
- Err(BindError::Fail(format!("INSTANCE_HOME not found.")))?
+ if !Path::new(vars.home()).exists() {
+ Err(BindError::Fail(format!("Specified home directory not found.")))?
}
Ok(())
}
@@ -40,10 +44,10 @@ impl Filesystem for HOME {
fn register(&self, args: &mut ExecutionArgs, vars: &InsVars) {
args.bind(vars.home(), vars.home_mount());
args.env("HOME", vars.home_mount());
- args.env("USER", vars.user());
+ args.env("USER", vars.user());
}
fn module(&self) -> &'static str {
- "HOME"
+ "home"
}
}
diff --git a/pacwrap-core/src/config/filesystem/root.rs b/pacwrap-core/src/config/filesystem/root.rs
index fd593d9..8f6080f 100644
--- a/pacwrap-core/src/config/filesystem/root.rs
+++ b/pacwrap-core/src/config/filesystem/root.rs
@@ -1,6 +1,6 @@
/*
* pacwrap-core
- *
+ *
* Copyright (C) 2023-2024 Xavier R.M.
* SPDX-License-Identifier: GPL-3.0-only
*
@@ -21,23 +21,27 @@ use std::path::Path;
use serde::{Deserialize, Serialize};
-use crate::{exec::args::ExecutionArgs,
- config::InsVars,
- config::filesystem::{Filesystem, BindError}};
+use crate::{
+ config::{
+ filesystem::{BindError, Filesystem},
+ InsVars,
+ },
+ exec::args::ExecutionArgs,
+};
#[derive(Debug, Clone, Serialize, Deserialize)]
-pub struct ROOT;
+pub struct Root;
-#[typetag::serde]
-impl Filesystem for ROOT {
+#[typetag::serde(name = "root")]
+impl Filesystem for Root {
fn check(&self, vars: &InsVars) -> Result<(), BindError> {
- if ! Path::new(vars.root()).exists() {
+ if !Path::new(vars.root()).exists() {
Err(BindError::Fail(format!("Container {} not found. ", vars.instance())))?
}
Ok(())
}
- fn register(&self, args: &mut ExecutionArgs, vars: &InsVars) {
+ fn register(&self, args: &mut ExecutionArgs, vars: &InsVars) {
args.robind(format!("{}/usr", vars.root()), "/usr");
args.robind(format!("{}/etc", vars.root()), "/etc");
args.symlink("/usr/lib", "/lib");
@@ -47,6 +51,6 @@ impl Filesystem for ROOT {
}
fn module(&self) -> &'static str {
- "ROOT"
+ "root"
}
}
diff --git a/pacwrap-core/src/config/filesystem/sys.rs b/pacwrap-core/src/config/filesystem/sys.rs
index fbb48c6..f101186 100644
--- a/pacwrap-core/src/config/filesystem/sys.rs
+++ b/pacwrap-core/src/config/filesystem/sys.rs
@@ -1,6 +1,6 @@
/*
* pacwrap-core
- *
+ *
* Copyright (C) 2023-2024 Xavier R.M.
* SPDX-License-Identifier: GPL-3.0-only
*
@@ -16,41 +16,44 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
use std::path::Path;
use serde::{Deserialize, Serialize};
-use crate::{exec::args::ExecutionArgs,
- config::InsVars,
- config::filesystem::{Filesystem, BindError}};
+use crate::{
+ config::{
+ filesystem::{BindError, Filesystem},
+ InsVars,
+ },
+ exec::args::ExecutionArgs,
+};
#[derive(Debug, Clone, Serialize, Deserialize)]
-struct SYSFS {
- #[serde(skip_serializing_if = "is_default_path", default = "default_path")]
- path: Vec
+struct System {
+ #[serde(skip_serializing_if = "is_default_path", default = "default_path")]
+ path: Vec,
}
-#[typetag::serde]
-impl Filesystem for SYSFS {
- fn check(&self, _vars: &InsVars) -> Result<(), BindError> {
+#[typetag::serde(name = "sysfs")]
+impl Filesystem for System {
+ fn check(&self, _vars: &InsVars) -> Result<(), BindError> {
for dir in self.path.iter() {
- if ! Path::new(&format!("/sys/{}",dir)).exists() {
+ if !Path::new(&format!("/sys/{}", dir)).exists() {
Err(BindError::Fail(format!("/sys/{} is inaccessible.", dir)))?
}
}
Ok(())
}
-
- fn register(&self, args: &mut ExecutionArgs, _: &InsVars) {
- for dir in self.path.iter() {
+
+ fn register(&self, args: &mut ExecutionArgs, _: &InsVars) {
+ for dir in self.path.iter() {
args.robind(format!("/sys/{}", dir), format!("/sys/{}", dir));
}
}
fn module(&self) -> &'static str {
- "SUSFS"
+ "sysfs"
}
}
@@ -59,9 +62,5 @@ fn is_default_path(path: &Vec) -> bool {
}
fn default_path() -> Vec {
- vec!("block".into(),
- "bus".into(),
- "class".into(),
- "dev".into(),
- "devices".into())
+ vec!["block".into(), "bus".into(), "class".into(), "dev".into(), "devices".into()]
}
diff --git a/pacwrap-core/src/config/filesystem/to_home.rs b/pacwrap-core/src/config/filesystem/to_home.rs
index b18129b..a3b025d 100644
--- a/pacwrap-core/src/config/filesystem/to_home.rs
+++ b/pacwrap-core/src/config/filesystem/to_home.rs
@@ -1,6 +1,6 @@
/*
* pacwrap-core
- *
+ *
* Copyright (C) 2023-2024 Xavier R.M.
* SPDX-License-Identifier: GPL-3.0-only
*
@@ -16,57 +16,48 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-#![allow(non_camel_case_types)]
-
use std::path::Path;
use serde::{Deserialize, Serialize};
-use crate::{exec::args::ExecutionArgs,
- config::InsVars,
- config::filesystem::{Filesystem,
- BindError,
- default_permission,
- is_default_permission},
- constants::HOME};
+use crate::{
+ config::{
+ filesystem::{default_permission, is_default_permission, BindError, Filesystem},
+ InsVars,
+ },
+ constants::HOME,
+ exec::args::ExecutionArgs,
+};
#[derive(Debug, Clone, Serialize, Deserialize)]
-pub struct TO_HOME {
- #[serde(skip_serializing_if = "is_default_permission", default = "default_permission")]
- permission: String,
- #[serde(skip_serializing_if = "Vec::is_empty", default)]
- path: Vec,
- #[serde(skip_serializing_if = "Vec::is_empty", default)]
- filesystem: Vec
+pub struct ToHome {
+ #[serde(skip_serializing_if = "Vec::is_empty", default, rename = "volumes")]
+ mounts: Vec,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
struct Mount {
- #[serde(skip_serializing_if = "is_default_permission", default = "default_permission")]
+ #[serde(skip_serializing_if = "is_default_permission", default = "default_permission")]
permission: String,
- #[serde(skip_serializing_if = "Vec::is_empty", default)]
- path: Vec
+ #[serde(skip_serializing_if = "String::is_empty", default)]
+ path: String,
+ #[serde(skip_serializing_if = "String::is_empty", default)]
+ dest: String,
}
-#[typetag::serde]
-impl Filesystem for TO_HOME {
+#[typetag::serde(name = "to_home")]
+impl Filesystem for ToHome {
fn check(&self, _vars: &InsVars) -> Result<(), BindError> {
- if self.path.len() > 0 {
- if let Err(e) = check_mount(&self.permission, &self.path[0]) {
- return Err(e);
- }
- } else {
- if self.filesystem.len() == 0 {
- Err(BindError::Warn(format!("Filesystem paths are undeclared.")))?
- }
+ if self.mounts.len() == 0 {
+ Err(BindError::Warn(format!("Mount volumes undeclared.")))?
}
- for m in self.filesystem.iter() {
+ for m in self.mounts.iter() {
if m.path.len() == 0 {
- Err(BindError::Warn(format!("Filesystem paths are undeclared.")))?
+ Err(BindError::Warn(format!("Mount volumes undeclared.")))?
}
- if let Err(e) = check_mount(&m.permission, &m.path[0]) {
+ if let Err(e) = check_mount(&m.permission, &m.path) {
return Err(e);
}
}
@@ -75,45 +66,38 @@ impl Filesystem for TO_HOME {
}
fn register(&self, args: &mut ExecutionArgs, vars: &InsVars) {
- if self.path.len() > 0 {
- bind_filesystem(args,vars, &self.permission, &self.path);
- }
-
- for m in self.filesystem.iter() {
- bind_filesystem(args,vars, &m.permission, &m.path);
+ for m in self.mounts.iter() {
+ bind_filesystem(args, vars, &m.permission, &m.path, &m.dest);
}
}
fn module(&self) -> &'static str {
- "TO_HOME"
+ "to_home"
}
}
-fn bind_filesystem(args: &mut ExecutionArgs, vars: &InsVars, permission: &str, path: &Vec) {
- let src = &path[0];
- let mut dest: &String = src;
-
- if path.len() > 1 {
- dest = &path[1];
- }
-
- let path_src = format!("{}/{}", *HOME, path[0]);
- let path_dest = format!("{}/{}", vars.home_mount(), dest);
+fn bind_filesystem(args: &mut ExecutionArgs, vars: &InsVars, permission: &str, src: &str, dest: &str) {
+ let dest = match dest.is_empty() {
+ false => dest,
+ true => src,
+ };
+ let dest = format!("{}/{}", vars.home_mount(), dest);
+ let src = format!("{}/{}", *HOME, src);
match permission == "rw" {
- false => args.robind(path_src, path_dest),
- true => args.bind(path_src, path_dest),
+ false => args.robind(src, dest),
+ true => args.bind(src, dest),
}
}
fn check_mount(permission: &String, path: &String) -> Result<(), BindError> {
- let per = permission.to_lowercase();
-
+ let per = permission.to_lowercase();
+
if per != "ro" && per != "rw" {
Err(BindError::Fail(format!("{} is an invalid permission.", permission)))?
}
- if ! Path::new(&format!("{}/{}", *HOME, &path)).exists() {
+ if !Path::new(&format!("{}/{}", *HOME, &path)).exists() {
Err(BindError::Fail(format!("~/{} not found.", path)))?
}
diff --git a/pacwrap-core/src/config/filesystem/to_root.rs b/pacwrap-core/src/config/filesystem/to_root.rs
index fcb27cb..f22a0c2 100644
--- a/pacwrap-core/src/config/filesystem/to_root.rs
+++ b/pacwrap-core/src/config/filesystem/to_root.rs
@@ -1,6 +1,6 @@
/*
* pacwrap-core
- *
+ *
* Copyright (C) 2023-2024 Xavier R.M.
* SPDX-License-Identifier: GPL-3.0-only
*
@@ -16,56 +16,47 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-#![allow(non_camel_case_types)]
-
use std::path::Path;
use serde::{Deserialize, Serialize};
-use crate::{exec::args::ExecutionArgs,
- config::InsVars,
- config::filesystem::{Filesystem,
- BindError,
- default_permission,
- is_default_permission}};
+use crate::{
+ config::{
+ filesystem::{default_permission, is_default_permission, BindError, Filesystem},
+ InsVars,
+ },
+ exec::args::ExecutionArgs,
+};
#[derive(Debug, Clone, Serialize, Deserialize)]
-pub struct TO_ROOT {
- #[serde(skip_serializing_if = "is_default_permission", default = "default_permission")]
- permission: String,
- #[serde(skip_serializing_if = "Vec::is_empty", default)]
- path: Vec,
- #[serde(skip_serializing_if = "Vec::is_empty", default)]
- filesystem: Vec
+pub struct ToRoot {
+ #[serde(skip_serializing_if = "Vec::is_empty", default, rename = "volumes")]
+ mounts: Vec,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
struct Mount {
- #[serde(skip_serializing_if = "is_default_permission", default = "default_permission")]
+ #[serde(skip_serializing_if = "is_default_permission", default = "default_permission")]
permission: String,
- #[serde(skip_serializing_if = "Vec::is_empty", default)]
- path: Vec
+ #[serde(skip_serializing_if = "String::is_empty", default)]
+ path: String,
+ #[serde(skip_serializing_if = "String::is_empty", default)]
+ dest: String,
}
-#[typetag::serde]
-impl Filesystem for TO_ROOT {
+#[typetag::serde(name = "to_root")]
+impl Filesystem for ToRoot {
fn check(&self, _vars: &InsVars) -> Result<(), BindError> {
- if self.path.len() > 0 {
- if let Err(e) = check_mount(&self.permission, &self.path[0]) {
- return Err(e);
- }
- } else {
- if self.filesystem.len() == 0 {
- Err(BindError::Warn(format!("Filesystem paths are undeclared.")))?
- }
+ if self.mounts.len() == 0 {
+ Err(BindError::Warn(format!("Mount volumes undeclared.")))?
}
- for m in self.filesystem.iter() {
+ for m in self.mounts.iter() {
if m.path.len() == 0 {
- Err(BindError::Warn(format!("Filesystem paths are undeclared.")))?
+ Err(BindError::Warn(format!("Mount volumes undeclared.")))?
}
- if let Err(e) = check_mount(&m.permission, &m.path[0]) {
+ if let Err(e) = check_mount(&m.permission, &m.path) {
return Err(e);
}
}
@@ -74,28 +65,22 @@ impl Filesystem for TO_ROOT {
}
fn register(&self, args: &mut ExecutionArgs, _vars: &InsVars) {
- if self.path.len() > 0 {
- bind_filesystem(args, &self.permission, &self.path);
- }
-
- for m in self.filesystem.iter() {
- bind_filesystem(args, &m.permission, &m.path);
+ for m in self.mounts.iter() {
+ bind_filesystem(args, &m.permission, &m.path, &m.dest);
}
}
fn module(&self) -> &'static str {
- "TO_HOME"
+ "to_root"
}
}
-fn bind_filesystem(args: &mut ExecutionArgs, permission: &str, path: &Vec) {
- let src = &path[0];
- let mut dest: &String = src;
+fn bind_filesystem(args: &mut ExecutionArgs, permission: &str, src: &str, dest: &str) {
+ let dest = match dest.is_empty() {
+ true => src,
+ false => dest,
+ };
- if path.len() > 1 {
- dest = &path[1];
- }
-
match permission == "rw" {
false => args.robind(src, dest),
true => args.bind(src, dest),
@@ -103,15 +88,15 @@ fn bind_filesystem(args: &mut ExecutionArgs, permission: &str, path: &Vec Result<(), BindError> {
- let per = permission.to_lowercase();
-
+ let per = permission.to_lowercase();
+
if per != "ro" && per != "rw" {
- Err(BindError::Fail(format!("{} is an invalid permission.", permission)))?
+ Err(BindError::Fail(format!("{} is an invalid permission.", permission)))?
}
- if ! Path::new(path).exists() {
- Err(BindError::Fail(format!("Source path not found.")))?
+ if !Path::new(path).exists() {
+ Err(BindError::Fail(format!("Source path not found.")))?
}
-
+
Ok(())
}
diff --git a/pacwrap-core/src/config/global.rs b/pacwrap-core/src/config/global.rs
index b59c627..d218921 100644
--- a/pacwrap-core/src/config/global.rs
+++ b/pacwrap-core/src/config/global.rs
@@ -1,6 +1,6 @@
/*
* pacwrap-core
- *
+ *
* Copyright (C) 2023-2024 Xavier R.M.
* SPDX-License-Identifier: GPL-3.0-only
*
@@ -20,9 +20,13 @@
use std::process::exit;
use lazy_static::lazy_static;
-use serde::{Serialize, Deserialize};
+use serde::{Deserialize, Serialize};
-use crate::{Result, config::{config, save}, constants::CONFIG_FILE};
+use crate::{
+ config::{config, save},
+ constants::CONFIG_FILE,
+ Result,
+};
lazy_static! {
pub static ref CONFIG: Global = Global::load();
@@ -58,27 +62,27 @@ impl Default for ProgressKind {
#[derive(Serialize, Deserialize, Clone)]
pub struct Global {
- #[serde(default = "Configuration::new")]
+ #[serde(default = "Configuration::new")]
config: Configuration,
- #[serde(default = "AlpmConfiguration::new")]
+ #[serde(default = "AlpmConfiguration::new")]
alpm: AlpmConfiguration,
}
#[derive(Serialize, Deserialize, Clone)]
pub struct Progress {
- #[serde(default = "ProgressKind::default")]
+ #[serde(default = "ProgressKind::default")]
transact: ProgressKind,
- #[serde(default = "ProgressKind::default")]
+ #[serde(default = "ProgressKind::default")]
download: ProgressKind,
}
#[derive(Serialize, Deserialize, Clone)]
pub struct Configuration {
- #[serde(default = "Verbosity::default")]
+ #[serde(default = "Verbosity::default")]
summary: Verbosity,
- #[serde(default = "Verbosity::default")]
+ #[serde(default = "Verbosity::default")]
logging: Verbosity,
- #[serde(default = "Progress::new")]
+ #[serde(default = "Progress::new")]
progress: Progress,
}
@@ -88,15 +92,15 @@ pub struct AlpmConfiguration {
ignore_pkg: Vec,
#[serde(default = "hold_pkg")]
hold_pkg: Vec,
- #[serde(default = "sig_level")]
+ #[serde(default = "sig_level")]
sig_level: String,
- #[serde(default = "sig_level_opt")]
+ #[serde(default = "sig_level_opt")]
sig_level_local: String,
- #[serde(default = "parallel_downloads")]
+ #[serde(default = "parallel_downloads")]
parallel_downloads: u32,
- #[serde(default = "default_true")]
+ #[serde(default = "default_true")]
check_space: bool,
- #[serde(default = "default_true")]
+ #[serde(default = "default_true")]
download_timeout: bool,
}
@@ -126,7 +130,7 @@ impl Progress {
fn new() -> Self {
Self {
transact: ProgressKind::CondensedForeign,
- download: ProgressKind::CondensedForeign,
+ download: ProgressKind::CondensedForeign,
}
}
}
@@ -136,8 +140,8 @@ impl AlpmConfiguration {
Self {
ignore_pkg: ignore_pkg(),
hold_pkg: hold_pkg(),
- sig_level: sig_level(),
- sig_level_local: sig_level_opt(),
+ sig_level: sig_level(),
+ sig_level_local: sig_level_opt(),
parallel_downloads: parallel_downloads(),
check_space: true,
download_timeout: true,
@@ -149,7 +153,7 @@ impl AlpmConfiguration {
}
pub fn download_timeout(&self) -> bool {
- ! self.download_timeout
+ !self.download_timeout
}
pub fn parallel_downloads(&self) -> u32 {
@@ -210,7 +214,7 @@ fn sig_level() -> String {
}
fn sig_level_opt() -> String {
- "Optional".into()
+ "Optional".into()
}
fn parallel_downloads() -> u32 {
diff --git a/pacwrap-core/src/config/init.rs b/pacwrap-core/src/config/init.rs
index fe9716b..02e77ba 100644
--- a/pacwrap-core/src/config/init.rs
+++ b/pacwrap-core/src/config/init.rs
@@ -1,6 +1,6 @@
/*
* pacwrap-core
- *
+ *
* Copyright (C) 2023-2024 Xavier R.M.
* SPDX-License-Identifier: GPL-3.0-only
*
@@ -17,14 +17,16 @@
* along with this program. If not, see .
*/
-use std::{path::Path, fs::File, io::Write};
+use std::{fs::File, io::Write, path::Path};
-use crate::{err,
- Error,
- Result,
- ErrorKind,
+use crate::{
+ config::global::CONFIG,
constants::{CACHE_DIR, CONFIG_DIR, DATA_DIR},
- config::global::CONFIG};
+ err,
+ Error,
+ ErrorKind,
+ Result,
+};
static REPO_CONF_DEFAULT: &'static str = r###"## See the pacman.conf(5) manpage for information on repository directives.
## All other libalpm-related options therein are ignored.
@@ -72,7 +74,7 @@ impl DirectoryLayout {
fn instantiate(self) -> Result<()> {
for dir in self.dirs {
let path: &str = &format!("{}{}", self.root, dir);
-
+
if Path::new(path).exists() {
continue;
}
@@ -88,22 +90,22 @@ impl DirectoryLayout {
fn data_layout() -> DirectoryLayout {
DirectoryLayout {
- dirs: vec!("/root", "/home", "/state", "/pacman/sync"),
+ dirs: vec!["/root", "/home", "/state", "/pacman/sync"],
root: *DATA_DIR,
}
}
fn cache_layout() -> DirectoryLayout {
DirectoryLayout {
- dirs: vec!("/pkg"),
- root: *CACHE_DIR
+ dirs: vec!["/pkg"],
+ root: *CACHE_DIR,
}
}
fn config_layout() -> DirectoryLayout {
DirectoryLayout {
- dirs: vec!("/instance"),
- root: *CONFIG_DIR
+ dirs: vec!["/instance"],
+ root: *CONFIG_DIR,
}
}
@@ -114,9 +116,9 @@ fn write_to_file(location: &str, contents: &str) -> Result<()> {
let mut f = match File::create(&location) {
Ok(f) => f,
- Err(error) => err!(ErrorKind::IOError(location.into(), error.kind()))?
+ Err(error) => err!(ErrorKind::IOError(location.into(), error.kind()))?,
};
-
+
if let Err(error) = write!(f, "{contents}") {
err!(ErrorKind::IOError(location.into(), error.kind()))?
}
@@ -125,11 +127,13 @@ fn write_to_file(location: &str, contents: &str) -> Result<()> {
}
pub fn init() -> Result<()> {
- let _ = *CONFIG;
-
config_layout().instantiate()?;
data_layout().instantiate()?;
cache_layout().instantiate()?;
write_to_file(&format!("{}/repositories.conf", *CONFIG_DIR), REPO_CONF_DEFAULT)?;
- write_to_file(&format!("{}/pacwrap.yml", *CONFIG_DIR), PACWRAP_CONF_DEFAULT)
+ write_to_file(&format!("{}/pacwrap.yml", *CONFIG_DIR), PACWRAP_CONF_DEFAULT)?;
+
+ let _ = *CONFIG;
+
+ Ok(())
}
diff --git a/pacwrap-core/src/config/instance.rs b/pacwrap-core/src/config/instance.rs
index 9afc416..2e7ca15 100644
--- a/pacwrap-core/src/config/instance.rs
+++ b/pacwrap-core/src/config/instance.rs
@@ -1,6 +1,6 @@
/*
* pacwrap-core
- *
+ *
* Copyright (C) 2023-2024 Xavier R.M.
* SPDX-License-Identifier: GPL-3.0-only
*
@@ -17,33 +17,39 @@
* along with this program. If not, see .
*/
-use std::{borrow::Cow,
- fmt::{Display, Debug, Formatter},
- vec::Vec};
+use std::{
+ borrow::Cow,
+ fmt::{Debug, Display, Formatter},
+ vec::Vec,
+};
use serde::{Deserialize, Serialize};
-use crate::{Result,
- config::{permission::{Permission, none::NONE},
- filesystem::{Filesystem, root::ROOT, home::HOME},
+use crate::{
+ config::{
dbus::Dbus,
- vars::InsVars,
- save},
- constants::UNIX_TIMESTAMP};
+ filesystem::{home::Home, root::Root, Filesystem},
+ permission::{none::None, Permission},
+ save,
+ vars::InsVars,
+ },
+ constants::UNIX_TIMESTAMP,
+ Result,
+};
#[derive(Serialize, Deserialize, Clone)]
pub struct Instance<'a> {
- #[serde(flatten)]
+ #[serde(flatten)]
metadata: InstanceMetadata<'a>,
#[serde(flatten)]
runtime: InstanceRuntime,
}
-impl <'a>Instance<'a> {
+impl<'a> Instance<'a> {
pub fn new(ctype: InstanceType, deps: Vec<&'a str>, pkgs: Vec<&'a str>) -> Self {
Self {
- metadata: InstanceMetadata::new(ctype,deps,pkgs),
- runtime: InstanceRuntime::new(),
+ metadata: InstanceMetadata::new(ctype, deps, pkgs),
+ runtime: InstanceRuntime::new(),
}
}
}
@@ -54,7 +60,7 @@ pub struct InstanceHandle<'a> {
vars: InsVars<'a>,
}
-impl <'a>InstanceHandle<'a> {
+impl<'a> InstanceHandle<'a> {
pub fn new(ins: Instance<'a>, ins_vars: InsVars<'a>) -> Self {
Self {
instance: ins,
@@ -87,7 +93,7 @@ impl <'a>InstanceHandle<'a> {
}
}
-impl <'a>Debug for InstanceHandle<'a> {
+impl<'a> Debug for InstanceHandle<'a> {
fn fmt(&self, fmter: &mut Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
write!(fmter, "{:?}", self.vars())?;
write!(fmter, "{:?}", self.config())
@@ -96,31 +102,31 @@ impl <'a>Debug for InstanceHandle<'a> {
#[derive(Serialize, Deserialize, Clone)]
pub struct InstanceRuntime {
- #[serde(default)]
- enable_userns: bool,
- #[serde(default)]
+ #[serde(default)]
+ enable_userns: bool,
+ #[serde(default)]
retain_session: bool,
#[serde(default = "default_true")]
seccomp: bool,
- #[serde(default)]
- allow_forking: bool,
- #[serde(skip_serializing_if = "Vec::is_empty", default)]
+ #[serde(default)]
+ allow_forking: bool,
+ #[serde(skip_serializing_if = "Vec::is_empty", default)]
filesystems: Vec>,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
permissions: Vec>,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
- dbus: Vec>,
+ dbus: Vec>,
}
impl InstanceRuntime {
pub fn new() -> Self {
- let default_fs: [Box; 2] = [Box::new(ROOT {}), Box::new(HOME {})];
- let default_per: [Box; 1] = [Box::new(NONE {})];
+ let default_fs: [Box; 2] = [Box::new(Root {}), Box::new(Home {})];
+ let default_per: [Box; 1] = [Box::new(None {})];
let fs: Vec> = Vec::from(default_fs);
- let per: Vec> = Vec::from(default_per);
-
+ let per: Vec> = Vec::from(default_per);
+
Self {
- seccomp: true,
+ seccomp: true,
allow_forking: false,
retain_session: false,
enable_userns: false,
@@ -130,28 +136,28 @@ impl InstanceRuntime {
}
}
- pub fn permissions(&self) -> &Vec> {
- &self.permissions
+ pub fn permissions(&self) -> &Vec> {
+ &self.permissions
}
-
- pub fn filesystem(&self) -> &Vec> {
- &self.filesystems
+
+ pub fn filesystem(&self) -> &Vec> {
+ &self.filesystems
}
-
- pub fn dbus(&self) -> &Vec> {
- &self.dbus
- }
-
- pub fn allow_forking(&self) -> &bool {
- &self.allow_forking
+
+ pub fn dbus(&self) -> &Vec> {
+ &self.dbus
}
-
- pub fn enable_userns(&self) -> &bool {
- &self.enable_userns
- }
-
- pub fn retain_session(&self) -> &bool {
- &self.retain_session
+
+ pub fn allow_forking(&self) -> &bool {
+ &self.allow_forking
+ }
+
+ pub fn enable_userns(&self) -> &bool {
+ &self.enable_userns
+ }
+
+ pub fn retain_session(&self) -> &bool {
+ &self.retain_session
}
pub fn seccomp(&self) -> &bool {
@@ -170,30 +176,19 @@ impl Debug for InstanceRuntime {
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Debug)]
pub enum InstanceType {
- LINK,
- BASE,
- DEP,
- ROOT
+ Symbolic,
+ Base,
+ Slice,
+ Aggregate,
}
-#[allow(dead_code)]
impl InstanceType {
- pub fn new(instype: &str) -> Self {
- match instype {
- "BASE" => Self::BASE,
- "ROOT" => Self::ROOT,
- "DEP" => Self::DEP,
- "LINK" => Self::LINK,
- _ => Self::BASE
- }
- }
-
fn as_str<'a>(&self) -> &'a str {
match self {
- Self::ROOT => "ROOT",
- Self::LINK => "LINK",
- Self::BASE => "BASE",
- Self::DEP => "DEP"
+ Self::Symbolic => "LINK",
+ Self::Base => "BASE",
+ Self::Slice => "DEP",
+ Self::Aggregate => "ROOT",
}
}
}
@@ -206,23 +201,23 @@ impl Display for InstanceType {
impl Default for InstanceType {
fn default() -> Self {
- Self::BASE
+ Self::Base
}
}
#[derive(Serialize, Deserialize, Clone)]
pub struct InstanceMetadata<'a> {
- #[serde(default)]
- container_type: InstanceType,
- #[serde(skip_serializing_if = "Vec::is_empty", default)]
- dependencies: Vec>,
- #[serde(skip_serializing_if = "Vec::is_empty", default)]
+ #[serde(default)]
+ container_type: InstanceType,
+ #[serde(skip_serializing_if = "Vec::is_empty", default)]
+ dependencies: Vec>,
+ #[serde(skip_serializing_if = "Vec::is_empty", default)]
explicit_packages: Vec>,
#[serde(default = "time_as_seconds")]
meta_version: u64,
}
-impl <'a>InstanceMetadata<'a> {
+impl<'a> InstanceMetadata<'a> {
fn new(ctype: InstanceType, deps: Vec<&'a str>, pkgs: Vec<&'a str>) -> Self {
Self {
container_type: ctype,
@@ -238,15 +233,15 @@ impl <'a>InstanceMetadata<'a> {
self.meta_version = *UNIX_TIMESTAMP;
}
- pub fn container_type(&self) -> &InstanceType {
- &self.container_type
+ pub fn container_type(&self) -> &InstanceType {
+ &self.container_type
}
- pub fn dependencies(&'a self) -> Vec<&'a str> {
+ pub fn dependencies(&'a self) -> Vec<&'a str> {
self.dependencies.iter().map(|a| a.as_ref()).collect()
}
-
- pub fn explicit_packages(&'a self) -> Vec<&'a str> {
+
+ pub fn explicit_packages(&'a self) -> Vec<&'a str> {
self.explicit_packages.iter().map(|a| a.as_ref()).collect()
}
diff --git a/pacwrap-core/src/config/permission.rs b/pacwrap-core/src/config/permission.rs
index 9f5f0d4..037ab33 100644
--- a/pacwrap-core/src/config/permission.rs
+++ b/pacwrap-core/src/config/permission.rs
@@ -1,6 +1,6 @@
/*
* pacwrap-core
- *
+ *
* Copyright (C) 2023-2024 Xavier R.M.
* SPDX-License-Identifier: GPL-3.0-only
*
@@ -21,21 +21,21 @@ use std::fmt::{Display, Formatter};
use crate::exec::args::ExecutionArgs;
-use dyn_clone::{DynClone, clone_trait_object};
+use dyn_clone::{clone_trait_object, DynClone};
-pub mod none;
+mod dev;
mod display;
-mod pulseaudio;
-mod pipewire;
mod env;
mod gpu;
mod net;
-mod dev;
+pub mod none;
+mod pipewire;
+mod pulseaudio;
pub enum Condition {
Success,
SuccessWarn(String),
- Nothing
+ Nothing,
}
#[derive(Debug, Clone)]
@@ -44,7 +44,7 @@ pub enum PermError {
Warn(String),
}
-#[typetag::serde(tag = "permission")]
+#[typetag::serde(tag = "module")]
pub trait Permission: DynClone {
fn check(&self) -> Result