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