format: fix formatting
This commit is contained in:
parent
e3552e9208
commit
9e102ffb52
12 changed files with 80 additions and 85 deletions
|
@ -1,9 +1,9 @@
|
|||
use crate::package::identifier::PackageLocator;
|
||||
use pkgfile::PKGFile;
|
||||
use reqwest::blocking::get;
|
||||
use std::error::Error;
|
||||
use std::fmt::Display;
|
||||
use std::io::Read;
|
||||
use pkgfile::PKGFile;
|
||||
use reqwest::blocking::get;
|
||||
use crate::package::identifier::PackageLocator;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum FetchError {
|
||||
|
@ -26,9 +26,8 @@ impl Error for FetchError {}
|
|||
|
||||
pub fn fetch_by_path<S: Into<String>>(path: S) -> Result<PKGFile, FetchError> {
|
||||
std::fs::read(path.into())
|
||||
.map_err(|e| FetchError::IOError(e)).and_then(|bytes| {
|
||||
PKGFile::try_from(bytes).map_err(|_| FetchError::ParseError)
|
||||
})
|
||||
.map_err(|e| FetchError::IOError(e))
|
||||
.and_then(|bytes| PKGFile::try_from(bytes).map_err(|_| FetchError::ParseError))
|
||||
}
|
||||
|
||||
pub fn fetch_by_uri<S: Into<String>>(uri: S) -> Result<PKGFile, FetchError> {
|
||||
|
|
|
@ -88,7 +88,7 @@ impl FromStr for PackageLocator {
|
|||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
#[allow(unused_assignments)] // false positive
|
||||
let mut name = None;
|
||||
let mut name = None;
|
||||
let mut version = None;
|
||||
let mut tags = None;
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ impl Display for BinError {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub enum BuildError {
|
||||
InvalidManifest
|
||||
InvalidManifest,
|
||||
}
|
||||
|
||||
impl Display for BuildError {
|
||||
|
@ -30,7 +30,7 @@ impl Display for BuildError {
|
|||
pub enum InstallError {
|
||||
BuildError(BuildError),
|
||||
BinError(BinError),
|
||||
Generic
|
||||
Generic,
|
||||
}
|
||||
|
||||
impl ToString for InstallError {
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
use std::fmt::Display;
|
||||
use log::{debug, trace};
|
||||
use crate::tmpfs::TempDir;
|
||||
use errors::{BinError, BuildError, InstallError};
|
||||
use log::{debug, trace};
|
||||
use manifest::Manifest;
|
||||
use pkgfile::PKGFile;
|
||||
use crate::tmpfs::TempDir;
|
||||
use std::fmt::Display;
|
||||
|
||||
pub mod errors;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum InstallType {
|
||||
Build,
|
||||
Bin
|
||||
Bin,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PackageInstaller {
|
||||
manifest: Manifest,
|
||||
pkgfile: PKGFile,
|
||||
install_type: InstallType
|
||||
install_type: InstallType,
|
||||
}
|
||||
|
||||
impl PackageInstaller {
|
||||
|
@ -25,7 +25,7 @@ impl PackageInstaller {
|
|||
PackageInstaller {
|
||||
manifest: m,
|
||||
pkgfile: p,
|
||||
install_type: i
|
||||
install_type: i,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,8 +46,8 @@ impl PackageInstaller {
|
|||
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)
|
||||
Ok(_) => {}
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
debug!("extracted package in: {}", tmpdir.to_string());
|
||||
Ok(())
|
||||
|
@ -60,14 +60,13 @@ impl PackageInstaller {
|
|||
let build_manifest = self.manifest.build.clone().unwrap();
|
||||
// TODO: Check dependencies
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn install(&self) -> Result<(), InstallError> {
|
||||
match self.install_type {
|
||||
InstallType::Bin => self.bin().map_err(|e| InstallError::BinError(e)),
|
||||
InstallType::Build => self.build().map_err(|e| InstallError::BuildError(e))
|
||||
InstallType::Build => self.build().map_err(|e| InstallError::BuildError(e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use log::trace;
|
||||
|
||||
pub mod fetch;
|
||||
pub mod identifier;
|
||||
pub mod installer;
|
||||
pub mod fetch;
|
||||
|
||||
pub struct Package {
|
||||
pub identifier: identifier::PackageIdentifier,
|
||||
|
@ -23,43 +23,47 @@ impl Package {
|
|||
}
|
||||
|
||||
/// Fetch a package from a package identifier.
|
||||
pub fn fetch(package_identifier: identifier::PackageIdentifier) -> Result<Package, fetch::FetchError> {
|
||||
pub fn fetch(
|
||||
package_identifier: identifier::PackageIdentifier,
|
||||
) -> Result<Package, fetch::FetchError> {
|
||||
match &package_identifier {
|
||||
identifier::PackageIdentifier::Path(path) => {
|
||||
trace!("fetching package from path: {}", path);
|
||||
let pkgfile = fetch::fetch_by_path(path).unwrap();
|
||||
Ok(Package::new(package_identifier, pkgfile))
|
||||
},
|
||||
}
|
||||
identifier::PackageIdentifier::URI(url) => {
|
||||
trace!("fetching package from uri: {}", url);
|
||||
let pkgfile = fetch::fetch_by_uri(url).unwrap();
|
||||
Ok(Package::new(package_identifier, pkgfile))
|
||||
},
|
||||
}
|
||||
identifier::PackageIdentifier::PackageLocator(locator) => {
|
||||
trace!("fetching package from locator: {}", locator);
|
||||
let pkgfile = fetch::fetch_by_package_locator(locator.clone()).unwrap();
|
||||
Ok(Package::new(package_identifier, pkgfile))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the package manifest.
|
||||
pub fn manifest(&self) -> manifest::Manifest {
|
||||
manifest::Manifest::try_from(self.pkgfile.manifest.clone())
|
||||
.unwrap()
|
||||
manifest::Manifest::try_from(self.pkgfile.manifest.clone()).unwrap()
|
||||
}
|
||||
|
||||
|
||||
/// Install the package.
|
||||
pub fn install(&mut self) -> Result<(), installer::errors::InstallError> {
|
||||
let manifest = self.manifest();
|
||||
let installer = installer::PackageInstaller::new(manifest.clone(), self.pkgfile.clone(), installer::InstallType::Bin);
|
||||
let installer = installer::PackageInstaller::new(
|
||||
manifest.clone(),
|
||||
self.pkgfile.clone(),
|
||||
installer::InstallType::Bin,
|
||||
);
|
||||
match installer.install() {
|
||||
Ok(_) => {
|
||||
self.is_installed = true;
|
||||
Ok(())
|
||||
},
|
||||
Err(e) => Err(e)
|
||||
}
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,4 +81,4 @@ impl Package {
|
|||
pub fn remove(&mut self) -> Result<(), ()> {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue