refactor: changed how packages work
This commit is contained in:
parent
9416794101
commit
3293e407ae
7 changed files with 134 additions and 59 deletions
|
@ -1,3 +1,68 @@
|
|||
use log::trace;
|
||||
|
||||
pub mod identifier;
|
||||
pub mod installer;
|
||||
pub mod fetch;
|
||||
pub mod fetch;
|
||||
|
||||
pub struct Package {
|
||||
pub identifier: identifier::PackageIdentifier,
|
||||
pub pkgfile: pkgfile::PKGFile,
|
||||
is_installed: bool,
|
||||
is_indexed: bool,
|
||||
}
|
||||
|
||||
impl Package {
|
||||
pub fn new(identifier: identifier::PackageIdentifier, pkgfile: pkgfile::PKGFile) -> Package {
|
||||
Package {
|
||||
identifier,
|
||||
pkgfile,
|
||||
is_installed: false,
|
||||
is_indexed: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn manifest(&self) -> manifest::Manifest {
|
||||
manifest::Manifest::try_from(self.pkgfile.manifest.clone())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
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))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
match installer.install() {
|
||||
Ok(_) => {
|
||||
self.is_installed = true;
|
||||
Ok(())
|
||||
},
|
||||
Err(e) => Err(e)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_installed(&self) -> bool {
|
||||
self.is_installed
|
||||
}
|
||||
|
||||
pub fn is_indexed(&self) -> bool {
|
||||
self.is_indexed
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue