Skip to content

Commit

Permalink
Support package management after the owner or repo changes
Browse files Browse the repository at this point in the history
fix #43
  • Loading branch information
innobead committed May 30, 2021
1 parent 4984e4a commit 6066859
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
12 changes: 10 additions & 2 deletions src/app/src/service/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ impl ItemOperationTrait for PackageService {

fn get(&self, name: &str) -> Result<Self::ItemInstance> {
debug!("Getting package: {}", name);
self.search(Some(name), None, None).map(|it| it[0].clone())

let results = self.search(Some(name), None, None)?;
if results.len() > 0 {
Ok(results.get(0).unwrap().to_owned())
} else {
Err(anyhow!("{} not found", name))
}
}
}

Expand Down Expand Up @@ -142,7 +148,9 @@ impl ItemSearchTrait for PackageService {

if let Some(name) = name {
debug!("Searching package by name: {}", name);
found_items.push(cache_service.get_package(name)?);
if let Ok(pkg) = cache_service.get_package(name) {
found_items.push(pkg);
}

return Ok(found_items);
}
Expand Down
26 changes: 21 additions & 5 deletions src/app/src/service/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use fs_extra::move_items;
use inflector::cases::uppercase::is_upper_case;
use is_executable::IsExecutable;
use libcli_rs::progress::{ProgressBar, ProgressTrait};
use log::{debug, info};
use log::{debug, error, info};
use regex::Captures;
use simpledi_rs::di::{DIContainer, DIContainerExtTrait, DependencyInjectTrait};
use symlink::{remove_symlink_dir, remove_symlink_file, symlink_dir, symlink_file};
Expand Down Expand Up @@ -747,11 +747,27 @@ impl ItemOperationTrait for ReleaseService {
let indexes: Vec<ReleaseIndex> = serde_yaml::from_reader(index_f)?;

for ri in indexes {
let pkg = pkg_service.get(&ri.name)?;
let p = config.installed_pkg_manifest_file(&pkg, &ri.version)?;
match pkg_service.get(&ri.name) {
Ok(pkg) => {
let p = config.installed_pkg_manifest_file(&pkg, &ri.version)?;

debug!("Reading {:?}", p);
match File::open(&p) {
Ok(f) => {
releases.push(serde_yaml::from_reader(f)?);
}
Err(e) => error!(
"Failed to read {:?} and ignored from the installed release list: {}",
p, e
),
}
}

let f = File::open(p)?;
releases.push(serde_yaml::from_reader(f)?);
Err(e) => {
error!("Failed to get {} package because the package probably removed from the repositories: {}", &ri.name, e);
continue;
}
}
}

Ok(releases)
Expand Down

0 comments on commit 6066859

Please sign in to comment.