aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/installer
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/src/installer')
-rw-r--r--crates/shirabe/src/installer/installation_manager.rs27
-rw-r--r--crates/shirabe/src/installer/installer_interface.rs4
-rw-r--r--crates/shirabe/src/installer/library_installer.rs30
-rw-r--r--crates/shirabe/src/installer/metapackage_installer.rs8
-rw-r--r--crates/shirabe/src/installer/noop_installer.rs12
-rw-r--r--crates/shirabe/src/installer/plugin_installer.rs4
-rw-r--r--crates/shirabe/src/installer/project_installer.rs6
7 files changed, 47 insertions, 44 deletions
diff --git a/crates/shirabe/src/installer/installation_manager.rs b/crates/shirabe/src/installer/installation_manager.rs
index 9517eada..3a04a8e9 100644
--- a/crates/shirabe/src/installer/installation_manager.rs
+++ b/crates/shirabe/src/installer/installation_manager.rs
@@ -198,22 +198,21 @@ impl InstallationManager {
/// Checks whether provided package is installed in one of the registered installers.
pub fn is_package_installed(
&self,
- repo: &dyn InstalledRepositoryInterface,
+ repo: &mut dyn InstalledRepositoryInterface,
package: PackageInterfaceHandle,
) -> anyhow::Result<bool> {
// For testing only (ref InstallationManagerMock::isPackageInstalled).
if self.mock.is_some() {
- return Ok(repo.has_package(package));
+ return repo.has_package(package);
}
if let Some(alias) = package.as_alias() {
let alias_of: PackageInterfaceHandle = alias.get_alias_of().into();
- return Ok(repo.has_package(package) && self.is_package_installed(repo, alias_of)?);
+ return Ok(repo.has_package(package)? && self.is_package_installed(repo, alias_of)?);
}
- Ok(self
- .get_installer(&package.get_type())?
- .is_installed(repo, package))
+ self.get_installer(&package.get_type())?
+ .is_installed(repo, package)
}
/// Install binary for the given package.
@@ -264,7 +263,7 @@ impl InstallationManager {
mock.updated.push((initial.clone(), target.clone()));
mock.trace.push(trace);
repo.remove_package(initial);
- if !repo.has_package(target.clone()) {
+ if !repo.has_package(target.clone())? {
repo.add_package(PackageInterfaceHandle::dup(&target));
}
}
@@ -278,7 +277,7 @@ impl InstallationManager {
let package: PackageInterfaceHandle = op.get_package().into();
mock.installed.push(package.clone());
mock.trace.push(trace);
- if !repo.has_package(package.clone()) {
+ if !repo.has_package(package.clone())? {
repo.add_package(PackageInterfaceHandle::dup(&package));
}
}
@@ -578,7 +577,7 @@ impl InstallationManager {
}
match &operation {
AnyOperation::MarkAliasInstalled(op) => {
- self.mark_alias_installed(&mut **repo.borrow_mut(), op);
+ self.mark_alias_installed(&mut **repo.borrow_mut(), op)?;
}
AnyOperation::MarkAliasUninstalled(op) => {
self.mark_alias_uninstalled(&mut **repo.borrow_mut(), op);
@@ -760,12 +759,14 @@ impl InstallationManager {
&self,
repo: &mut dyn InstalledRepositoryInterface,
operation: &MarkAliasInstalledOperation,
- ) {
+ ) -> anyhow::Result<()> {
let package = operation.get_package();
- if !repo.has_package(package.clone().into()) {
+ if !repo.has_package(package.clone().into())? {
repo.add_package(crate::package::PackageInterfaceHandle::dup(&package.into()));
}
+
+ Ok(())
}
/// Executes markAlias operation.
@@ -1016,7 +1017,7 @@ pub trait InstallationManagerInterface: std::fmt::Debug {
fn disable_plugins(&mut self);
fn is_package_installed(
&mut self,
- repo: &dyn InstalledRepositoryInterface,
+ repo: &mut dyn InstalledRepositoryInterface,
package: PackageInterfaceHandle,
) -> anyhow::Result<bool>;
fn ensure_binaries_presence(&mut self, package: PackageInterfaceHandle);
@@ -1052,7 +1053,7 @@ impl InstallationManagerInterface for InstallationManager {
fn is_package_installed(
&mut self,
- repo: &dyn InstalledRepositoryInterface,
+ repo: &mut dyn InstalledRepositoryInterface,
package: PackageInterfaceHandle,
) -> anyhow::Result<bool> {
InstallationManager::is_package_installed(self, repo, package)
diff --git a/crates/shirabe/src/installer/installer_interface.rs b/crates/shirabe/src/installer/installer_interface.rs
index 6edaddb7..f2c0cd7c 100644
--- a/crates/shirabe/src/installer/installer_interface.rs
+++ b/crates/shirabe/src/installer/installer_interface.rs
@@ -12,9 +12,9 @@ pub trait InstallerInterface: std::fmt::Debug {
fn is_installed(
&self,
- repo: &dyn InstalledRepositoryInterface,
+ repo: &mut dyn InstalledRepositoryInterface,
package: PackageInterfaceHandle,
- ) -> bool;
+ ) -> anyhow::Result<bool>;
async fn download(
&self,
diff --git a/crates/shirabe/src/installer/library_installer.rs b/crates/shirabe/src/installer/library_installer.rs
index 8efd985a..976c5a1f 100644
--- a/crates/shirabe/src/installer/library_installer.rs
+++ b/crates/shirabe/src/installer/library_installer.rs
@@ -241,32 +241,32 @@ impl InstallerInterface for LibraryInstaller {
fn is_installed(
&self,
- repo: &dyn InstalledRepositoryInterface,
+ repo: &mut dyn InstalledRepositoryInterface,
package: PackageInterfaceHandle,
- ) -> bool {
- if !repo.has_package(package.clone()) {
- return false;
+ ) -> anyhow::Result<bool> {
+ if !repo.has_package(package.clone())? {
+ return Ok(false);
}
let install_path = self.get_install_path(package).unwrap();
if Filesystem::is_readable(&install_path) {
- return true;
+ return Ok(true);
}
if Platform::is_windows() && self.filesystem.borrow_mut().is_junction(&install_path) {
- return true;
+ return Ok(true);
}
if is_link(&install_path) {
if realpath(&install_path).is_none() {
- return false;
+ return Ok(false);
}
- return true;
+ return Ok(true);
}
- false
+ Ok(false)
}
async fn download(
@@ -322,7 +322,9 @@ impl InstallerInterface for LibraryInstaller {
let download_path = self.get_install_path(package.clone()).unwrap();
// remove the binaries if it appears the package files are missing
- if !Filesystem::is_readable(&download_path) && repo.borrow().has_package(package.clone()) {
+ if !Filesystem::is_readable(&download_path)
+ && repo.borrow_mut().has_package(package.clone())?
+ {
self.binary_installer
.borrow_mut()
.remove_binaries(package.clone());
@@ -335,7 +337,7 @@ impl InstallerInterface for LibraryInstaller {
.borrow_mut()
.install_binaries(package.clone(), &install_path, true);
let mut repo = repo.borrow_mut();
- if !repo.has_package(package.clone()) {
+ if !repo.has_package(package.clone())? {
repo.add_package(PackageInterfaceHandle::dup(&package));
}
@@ -348,7 +350,7 @@ impl InstallerInterface for LibraryInstaller {
initial: PackageInterfaceHandle,
target: PackageInterfaceHandle,
) -> anyhow::Result<Option<PhpMixed>> {
- if !repo.borrow().has_package(initial.clone()) {
+ if !repo.borrow_mut().has_package(initial.clone())? {
return Err(InvalidArgumentException {
message: format!("Package is not installed: {}", initial),
code: 0,
@@ -369,7 +371,7 @@ impl InstallerInterface for LibraryInstaller {
.install_binaries(target.clone(), &install_path, true);
let mut repo = repo.borrow_mut();
repo.remove_package(initial.clone());
- if !repo.has_package(target.clone()) {
+ if !repo.has_package(target.clone())? {
repo.add_package(PackageInterfaceHandle::dup(&target));
}
@@ -381,7 +383,7 @@ impl InstallerInterface for LibraryInstaller {
repo: &std::cell::RefCell<&mut dyn InstalledRepositoryInterface>,
package: PackageInterfaceHandle,
) -> anyhow::Result<Option<PhpMixed>> {
- if !repo.borrow().has_package(package.clone()) {
+ if !repo.borrow_mut().has_package(package.clone())? {
return Err(InvalidArgumentException {
message: format!("Package is not installed: {}", package),
code: 0,
diff --git a/crates/shirabe/src/installer/metapackage_installer.rs b/crates/shirabe/src/installer/metapackage_installer.rs
index cb6d13c3..26032a6d 100644
--- a/crates/shirabe/src/installer/metapackage_installer.rs
+++ b/crates/shirabe/src/installer/metapackage_installer.rs
@@ -30,9 +30,9 @@ impl InstallerInterface for MetapackageInstaller {
fn is_installed(
&self,
- repo: &dyn InstalledRepositoryInterface,
+ repo: &mut dyn InstalledRepositoryInterface,
package: PackageInterfaceHandle,
- ) -> bool {
+ ) -> anyhow::Result<bool> {
repo.has_package(package)
}
@@ -85,7 +85,7 @@ impl InstallerInterface for MetapackageInstaller {
initial: PackageInterfaceHandle,
target: PackageInterfaceHandle,
) -> anyhow::Result<Option<PhpMixed>> {
- if !repo.borrow().has_package(initial.clone()) {
+ if !repo.borrow_mut().has_package(initial.clone())? {
return Err(InvalidArgumentException {
message: format!("Package is not installed: {}", initial),
code: 0,
@@ -114,7 +114,7 @@ impl InstallerInterface for MetapackageInstaller {
repo: &std::cell::RefCell<&mut dyn InstalledRepositoryInterface>,
package: PackageInterfaceHandle,
) -> anyhow::Result<Option<PhpMixed>> {
- if !repo.borrow().has_package(package.clone()) {
+ if !repo.borrow_mut().has_package(package.clone())? {
return Err(InvalidArgumentException {
message: format!("Package is not installed: {}", package),
code: 0,
diff --git a/crates/shirabe/src/installer/noop_installer.rs b/crates/shirabe/src/installer/noop_installer.rs
index c83bf674..d76ad4ad 100644
--- a/crates/shirabe/src/installer/noop_installer.rs
+++ b/crates/shirabe/src/installer/noop_installer.rs
@@ -16,9 +16,9 @@ impl InstallerInterface for NoopInstaller {
fn is_installed(
&self,
- repo: &dyn InstalledRepositoryInterface,
+ repo: &mut dyn InstalledRepositoryInterface,
package: PackageInterfaceHandle,
- ) -> bool {
+ ) -> anyhow::Result<bool> {
repo.has_package(package)
}
@@ -54,7 +54,7 @@ impl InstallerInterface for NoopInstaller {
package: PackageInterfaceHandle,
) -> anyhow::Result<Option<PhpMixed>> {
let mut repo = repo.borrow_mut();
- if !repo.has_package(package.clone()) {
+ if !repo.has_package(package.clone())? {
repo.add_package(PackageInterfaceHandle::dup(&package));
}
@@ -68,7 +68,7 @@ impl InstallerInterface for NoopInstaller {
target: PackageInterfaceHandle,
) -> anyhow::Result<Option<PhpMixed>> {
let mut repo = repo.borrow_mut();
- if !repo.has_package(initial.clone()) {
+ if !repo.has_package(initial.clone())? {
return Err(InvalidArgumentException {
message: format!("Package is not installed: {}", initial),
code: 0,
@@ -77,7 +77,7 @@ impl InstallerInterface for NoopInstaller {
}
repo.remove_package(initial);
- if !repo.has_package(target.clone()) {
+ if !repo.has_package(target.clone())? {
repo.add_package(PackageInterfaceHandle::dup(&target));
}
@@ -90,7 +90,7 @@ impl InstallerInterface for NoopInstaller {
package: PackageInterfaceHandle,
) -> anyhow::Result<Option<PhpMixed>> {
let mut repo = repo.borrow_mut();
- if !repo.has_package(package.clone()) {
+ if !repo.has_package(package.clone())? {
return Err(InvalidArgumentException {
message: format!("Package is not installed: {}", package),
code: 0,
diff --git a/crates/shirabe/src/installer/plugin_installer.rs b/crates/shirabe/src/installer/plugin_installer.rs
index 86c579b2..c0473fd0 100644
--- a/crates/shirabe/src/installer/plugin_installer.rs
+++ b/crates/shirabe/src/installer/plugin_installer.rs
@@ -79,9 +79,9 @@ impl InstallerInterface for PluginInstaller {
fn is_installed(
&self,
- repo: &dyn InstalledRepositoryInterface,
+ repo: &mut dyn InstalledRepositoryInterface,
package: PackageInterfaceHandle,
- ) -> bool {
+ ) -> anyhow::Result<bool> {
self.inner.is_installed(repo, package)
}
diff --git a/crates/shirabe/src/installer/project_installer.rs b/crates/shirabe/src/installer/project_installer.rs
index 0f2c3ba6..628e4252 100644
--- a/crates/shirabe/src/installer/project_installer.rs
+++ b/crates/shirabe/src/installer/project_installer.rs
@@ -37,10 +37,10 @@ impl InstallerInterface for ProjectInstaller {
fn is_installed(
&self,
- _repo: &dyn InstalledRepositoryInterface,
+ _repo: &mut dyn InstalledRepositoryInterface,
_package: PackageInterfaceHandle,
- ) -> bool {
- false
+ ) -> anyhow::Result<bool> {
+ Ok(false)
}
async fn download(