feat: prompts, dir structure, etc.
This commit is contained in:
parent
fc3ae1e71a
commit
89e62ad9c7
7 changed files with 94 additions and 20 deletions
|
@ -37,8 +37,8 @@ pub enum InstallError {
|
|||
impl ToString for InstallError {
|
||||
fn to_string(&self) -> String {
|
||||
match self {
|
||||
InstallError::BuildError(e) => format!("Build error: \n{}", e),
|
||||
InstallError::BinError(e) => format!("Bin error: \n{}", e),
|
||||
InstallError::BuildError(e) => format!("{}", e),
|
||||
InstallError::BinError(e) => format!("{}", e),
|
||||
InstallError::InvalidManifest => "Invalid manifest".to_string(),
|
||||
InstallError::Generic => "Install error".to_string(),
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use std::fs::{remove_dir, remove_dir_all};
|
||||
use std::process::exit;
|
||||
|
||||
use log::{debug, error, info, trace};
|
||||
|
@ -11,6 +12,8 @@ use crate::package::identifier::{PackageIdentifier, PackageLocator};
|
|||
use crate::package::Package;
|
||||
use crate::tmpfs::TempDir;
|
||||
use crate::types::fetch::TryFetch;
|
||||
use crate::util::{visit_dirs};
|
||||
use crate::util::prompts::prompt_bool;
|
||||
|
||||
pub mod errors;
|
||||
|
||||
|
@ -40,11 +43,14 @@ impl PackageInstaller {
|
|||
if !self.pkgfile.has_data() {
|
||||
return Err(BinError::UnpackError("package has no data".to_string()));
|
||||
}
|
||||
if std::path::Path::new(&path).exists() {
|
||||
return Err(BinError::UnpackError(format!(
|
||||
"path already exists: {}",
|
||||
path
|
||||
)));
|
||||
let path = std::path::Path::new(&path);
|
||||
if path.exists() {
|
||||
trace!("cache already exists..");
|
||||
debug!("removing cache dir...");
|
||||
match remove_dir_all(path) {
|
||||
Ok(_) => debug!("removed cache directory"),
|
||||
Err(e) => return Err(BinError::UnpackError(format!("unable to remove directory ({}): {}", path.to_str().unwrap_or("unknown"), e.to_string())))
|
||||
}
|
||||
}
|
||||
tar::Archive::new(self.pkgfile.data.as_slice())
|
||||
.unpack(&path)
|
||||
|
@ -55,14 +61,27 @@ impl PackageInstaller {
|
|||
let mut tmpdir = TempDir::default();
|
||||
tmpdir.push(&self.manifest.package.name);
|
||||
trace!("extracting package into: {}", tmpdir.to_string());
|
||||
match self.extract_to(tmpdir.to_string()) {
|
||||
Ok(_) => {}
|
||||
Err(e) => return Err(e),
|
||||
if let Err(e) = self.extract_to(tmpdir.to_string()) {
|
||||
return Err(e)
|
||||
}
|
||||
debug!("extracted package in: {}", tmpdir.to_string());
|
||||
if prompt_bool("See all files?", false) {
|
||||
if let Err(e) = visit_dirs(tmpdir.path().as_path(), &|d| info!(target: "item", "{}", d.path().to_str().unwrap())) {
|
||||
error!("Could not show files: {}", e);
|
||||
}
|
||||
if prompt_bool("Continue?", false) {
|
||||
self.apply_overlay();
|
||||
}
|
||||
} else {
|
||||
self.apply_overlay();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn apply_overlay(&self) {
|
||||
|
||||
}
|
||||
|
||||
fn build(&self) -> Result<(), BuildError> {
|
||||
if let None = self.manifest.build.clone() {
|
||||
return Err(BuildError::InvalidManifest);
|
||||
|
@ -80,7 +99,7 @@ impl PackageInstaller {
|
|||
match pkg.install(CONFIG.with(|c| {
|
||||
c.build_by_default
|
||||
})) {
|
||||
Ok(_) => { info!("Installed dependency: \"{}\"", pkg.manifest().package.name) },
|
||||
Ok(_) => { info!("Installed dependency: \"{}\"", pkg.manifest().package.name) }
|
||||
Err(_) => {
|
||||
error!("Could not install dependency: \"{}\"", pkg.identifier);
|
||||
exit(1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue