Skip to content

Commit eb82a25

Browse files
committed
handle invalid repos
1 parent 7bc0417 commit eb82a25

File tree

6 files changed

+23
-24
lines changed

6 files changed

+23
-24
lines changed

Cargo.lock

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ zip = "0.6.6"
2323
serde_ini = "0.2.0"
2424
regex = "1.10.2"
2525
async-recursion = "1.0.5"
26-
openssl = { version = "0.10.45", features = ["vendored"] }
26+
# openssl = { version = "0.10.45", features = ["vendored"] }
27+
openssl = "0.10.45"
2728
url = "2.2"
2829
walkdir = "2.4.0"
2930

src/android_root.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ pub fn get_downloads_dir() -> String {
2020

2121
pub fn is_mmrl() -> bool {
2222
return match env::var("MMRL_INTR") {
23-
Ok(val) => true,
24-
Err(e) => false,
23+
Ok(_val) => true,
24+
Err(_e) => false,
2525
};
2626
}
2727

src/cmd/repo.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn add_repos_to_json(file_path: &str, new_repos: Vec<String>) -> io::Result<()>
3232
if !repos.contains(&repo_value) {
3333
repos.push(repo_value);
3434
} else {
35-
println!("\"{}\" has been already added", repo)
35+
println!("- \"{}\" has been already added", repo)
3636
}
3737
}
3838
} else {
@@ -53,11 +53,11 @@ pub async fn add(url: Vec<String>) -> () {
5353
let file_path = "/data/adb/mmrl/repos.json";
5454
match add_repos_to_json(file_path, url) {
5555
Ok(_) => {
56-
println!("Repositories added successfully.");
56+
println!("- Repositories added successfully.");
5757
exit(0)
5858
}
5959
Err(e) => {
60-
eprintln!("Error adding repositories: {}", e);
60+
eprintln!("! Error adding repositories: {}", e);
6161
exit(500)
6262
}
6363
}

src/main.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use android_root::module_state;
1313
use clap::{Parser, Subcommand};
1414
use cmd::install::install_local;
1515
use repo::Repo;
16+
use serde_json::json;
1617
use std::io::Write;
1718
use std::{
1819
fs::{self, File},
@@ -181,16 +182,23 @@ async fn main() {
181182
let file = File::open(REPOS_SOURCE).expect("file should open read only");
182183
let contents: Vec<String> = serde_json::from_reader(file).unwrap();
183184

184-
let mut tasks = vec![];
185+
let mut repos = vec![];
185186

186187
for url in contents {
187-
let task = tokio::spawn(fetch_repos(url));
188-
tasks.push(task);
188+
let repo = tokio::spawn(fetch_repos(url.clone()));
189+
let result = repo.await.unwrap();
190+
191+
let _repo = match result {
192+
Ok(data) => repos.push(data),
193+
Err(_e) => {
194+
repos.push(serde_json::from_str(r#"{ "name": "", "metadata": { "version": 666, "timestamp": 666 }, "modules": [] }"#).unwrap());
195+
println!("! Unable to fetch \"{}\", pushed empty data", url);
196+
}
197+
};
189198
}
190199

191-
for task in tasks {
192-
let result = task.await.unwrap();
193-
modules.append(&mut result.unwrap().modules);
200+
for mut repo in repos {
201+
modules.append(&mut repo.modules);
194202
}
195203

196204
match args.commands {

src/repo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub struct Version {
5858
pub(crate) fn find_module(modules: &Vec<Module>, id: String) -> Module {
5959
let module_exists = modules.iter().any(|m| m.id == id);
6060
if !module_exists {
61-
eprintln!("Unable to find {}", id);
61+
eprintln!("! Unable to find {}", id);
6262
exit(1);
6363
}
6464
let module_pos = modules.iter().position(|m| m.id == id).unwrap();
@@ -71,7 +71,7 @@ pub(crate) fn find_version(versions: Vec<Version>, version_name: String) -> Vers
7171
} else {
7272
let version_exists = versions.iter().any(|v| v.version == version_name);
7373
if !version_exists {
74-
println!("Unable to find {}", version_name);
74+
println!("! Unable to find {}", version_name);
7575
exit(1);
7676
}
7777
let version_pos = versions

0 commit comments

Comments
 (0)