Handle Symbolic containers properly
This commit is contained in:
parent
2dd3f1dbf1
commit
21b4fa6c32
5 changed files with 27 additions and 25 deletions
|
@ -19,6 +19,7 @@
|
|||
use std::{
|
||||
fmt::{Display, Formatter, Result as FmtResult},
|
||||
fs::{create_dir, create_dir_all},
|
||||
os::unix::fs::symlink,
|
||||
path::Path,
|
||||
process::exit,
|
||||
};
|
||||
|
@ -189,7 +190,14 @@ pub fn instantiate_container<'a>(handle: &'a ContainerHandle<'a>) -> Result<()>
|
|||
let root = handle.vars().root();
|
||||
let home = handle.vars().home();
|
||||
|
||||
create_dir(root).prepend_io(|| root.into())?;
|
||||
if let ContainerType::Symbolic = instype {
|
||||
let dep = handle.metadata().dependencies();
|
||||
let dep = dep.last().expect("Dependency element");
|
||||
|
||||
symlink(dep, root).prepend_io(|| root.into())?;
|
||||
} else {
|
||||
create_dir(root).prepend_io(|| root.into())?;
|
||||
}
|
||||
|
||||
if let ContainerType::Aggregate | ContainerType::Base = instype {
|
||||
if !Path::new(home).exists() {
|
||||
|
|
|
@ -86,7 +86,11 @@ fn compose_handles<'a>(
|
|||
for (instance, config) in compose {
|
||||
let handle = compose_handle(instance, config)?;
|
||||
|
||||
if let ContainerType::Base = handle.metadata().container_type() {
|
||||
if let ContainerType::Symbolic = handle.metadata().container_type() {
|
||||
if handle.metadata().dependencies().is_empty() {
|
||||
err!(ErrorKind::Message("Symbolic containers require at least one dependency."))?;
|
||||
}
|
||||
} else if let ContainerType::Base = handle.metadata().container_type() {
|
||||
if handle.metadata().dependencies().len() > 0 {
|
||||
err!(ErrorKind::Message("Dependencies cannot be assigned to base containers."))?;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use pacwrap_core::{
|
||||
config::{cache, init::init},
|
||||
config::{cache, init::init, ContainerType},
|
||||
err,
|
||||
error::*,
|
||||
lock::Lock,
|
||||
|
@ -30,6 +30,7 @@ use pacwrap_core::{
|
|||
arguments::{Arguments, InvalidArgument::*, Operand as Op},
|
||||
check_root,
|
||||
},
|
||||
ErrorKind,
|
||||
};
|
||||
|
||||
use crate::utils::delete::remove_containers;
|
||||
|
@ -101,7 +102,10 @@ fn engage_aggregator<'a>(
|
|||
Op::Short('t') | Op::Long("target") => match args.next() {
|
||||
Some(arg) => match arg {
|
||||
Op::ShortPos('t', target) | Op::LongPos("target", target) => {
|
||||
cache.get_instance(target)?;
|
||||
if let ContainerType::Symbolic = cache.get_instance(target)?.metadata().container_type() {
|
||||
err!(ErrorKind::Message("Symbolic containers cannot be transacted."))?;
|
||||
}
|
||||
|
||||
current_target = Some(target);
|
||||
targets.push(target);
|
||||
}
|
||||
|
|
|
@ -220,8 +220,8 @@ fn engage_aggregator<'a>(
|
|||
create = init;
|
||||
} else if let (true, None) = (create, container_type) {
|
||||
err!(ErrorKind::Message("Container type not specified."))?;
|
||||
} else {
|
||||
cache.get_instance(target)?;
|
||||
} else if let ContainerType::Symbolic = cache.get_instance(target)?.metadata().container_type() {
|
||||
err!(ErrorKind::Message("Symbolic containers cannot be transacted."))?;
|
||||
}
|
||||
}
|
||||
_ => args.invalid_operand()?,
|
||||
|
|
|
@ -17,22 +17,16 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use std::{
|
||||
fs::{create_dir, read_link},
|
||||
os::unix::fs::symlink,
|
||||
path::Path,
|
||||
};
|
||||
|
||||
use pacwrap_core::{
|
||||
config::{cache, ConfigError, Container, ContainerHandle, ContainerType, ContainerVariables},
|
||||
constants::{ARROW_CYAN, ARROW_GREEN, BOLD, RESET},
|
||||
err,
|
||||
sync::instantiate_container,
|
||||
utils::{
|
||||
arguments::{InvalidArgument, Operand},
|
||||
Arguments,
|
||||
},
|
||||
Error,
|
||||
ErrorGeneric,
|
||||
Result,
|
||||
};
|
||||
|
||||
|
@ -74,25 +68,17 @@ pub fn link(args: &mut Arguments) -> Result<()> {
|
|||
ContainerHandle::new(container, container_vars)
|
||||
} else {
|
||||
let container_vars = ContainerVariables::new(src);
|
||||
let mut deps = dest_handle.metadata().dependencies();
|
||||
let mut handle = ContainerHandle::from(dest_handle, container_vars);
|
||||
|
||||
deps.push(dest_handle.vars().instance());
|
||||
handle.metadata_mut().set_type(ContainerType::Symbolic);
|
||||
handle.metadata_mut().set_metadata(vec![], vec![]);
|
||||
handle.metadata_mut().set_metadata(deps, vec![]);
|
||||
handle
|
||||
},
|
||||
};
|
||||
let home = src_handle.vars().home();
|
||||
let root = src_handle.vars().root();
|
||||
|
||||
if Path::new(root).exists() || read_link(root).is_ok() {
|
||||
err!(ConfigError::AlreadyExists(src.to_string()))?;
|
||||
}
|
||||
|
||||
if !Path::new(home).exists() {
|
||||
create_dir(home).prepend_io(|| home.into())?;
|
||||
}
|
||||
|
||||
symlink(dest_handle.vars().instance(), src_handle.vars().root()).prepend_io(|| src_handle.vars().root().into())?;
|
||||
instantiate_container(&src_handle)?;
|
||||
src_handle.save()?;
|
||||
eprintln!(
|
||||
"{} Created symbolic container '{}{src}{}' {} '{}{dest}{}'.",
|
||||
|
|
Loading…
Reference in a new issue