Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(setup): critical errors when setup application #443

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions public/locales/af/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
"utilization": "Benutting",
"mode": "Modus",
"day": "Dag",
"shutting-down": "Afskakel.."
}
"shutting-down": "Afskakel..",
"critical-error": "Critical error",
"please-try-again-later": "Please try again later. If the problem persists, please contact us.",
"close-tari-universe": "Close Tari Universe"
}
5 changes: 4 additions & 1 deletion public/locales/cn/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
"day": "天",
"shutting-down": "停工..",
"tari-universe": "Tari Universe",
"testnet": "测试网"
"testnet": "测试网",
"critical-error": "Critical error",
"please-try-again-later": "Please try again later. If the problem persists, please contact us.",
"close-tari-universe": "Close Tari Universe"
}
5 changes: 4 additions & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
"day": "Day",
"shutting-down": "Shutting down..",
"tari-universe": "Tari Universe",
"testnet": "Testnet"
"testnet": "Testnet",
"critical-error": "Critical error",
"please-try-again-later": "Please try again later. If the problem persists, please contact us.",
"close-tari-universe": "Close Tari Universe"
}
7 changes: 5 additions & 2 deletions public/locales/pl/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
"utilization": "Wykorzystanie",
"mode": "Tryb",
"day": "Dzień",
"shutting-down": "Wyłączanie.."
}
"shutting-down": "Wyłączanie..",
"critical-error": "Krytyczny błąd",
"please-try-again-later": "Spróbuj ponownie później. Jeśli problem będzie się powtarzał, skontaktuj się z nami.",
"close-tari-universe": "Zamknij Tari Universe"
}
7 changes: 5 additions & 2 deletions public/locales/tr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
"day": "Gün",
"shutting-down": "Kapatılıyor..",
"tari-universe": "Tari Universe",
"testnet": "Testnet"
}
"testnet": "Testnet",
"critical-error": "Critical error",
"please-try-again-later": "Please try again later. If the problem persists, please contact us.",
"close-tari-universe": "Close Tari Universe"
}
137 changes: 68 additions & 69 deletions src-tauri/src/binary_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::{Arc, LazyLock};

use anyhow::{anyhow, Error};
use async_trait::async_trait;
use log::{debug, error, warn};
use log::{debug, error, info, warn};
use regex::Regex;
use semver::{Version, VersionReq};
use tari_common::configuration::Network;
Expand Down Expand Up @@ -379,80 +379,79 @@ impl BinaryResolver {
binary: Binaries,
progress_tracker: ProgressTracker,
) -> Result<Version, Error> {
let adapter = self
.adapters
.get(&binary)
.ok_or_else(|| anyhow!("No latest version adapter for this binary"))?;
let bin_folder = adapter.get_binary_folder();
let version_folders_list = match std::fs::read_dir(&bin_folder) {
Ok(list) => list,
Err(_) => match std::fs::create_dir_all(&bin_folder) {
Ok(_) => std::fs::read_dir(&bin_folder).unwrap(),
Err(e) => {
return Err(anyhow!("Failed to create dir: {}", e));
}
},
};
let mut versions = vec![];
for entry in version_folders_list {
let entry = match entry {
Ok(entry) => entry,
Err(_) => continue,
};
let path = entry.path();
if path.is_dir() {
// Check for actual binary existing. It can happen that the folder is there,
// for in_progress downloads or perhaps the antivirus has quarantined the file
let mut executable_name = get_binary_name(binary, path.clone())?;

if cfg!(target_os = "windows") {
executable_name = executable_name.with_extension("exe");
}

if !executable_name.exists() {
continue;
}

let version = path.file_name().unwrap().to_str().unwrap();
let version_typed = Version::parse(version).unwrap();
if adapter.is_version_allowed(&version_typed) {
versions.push(version_typed);
} else {
warn!(target: LOG_TARGET, "Version {} is not allowed", version);
}
}
}

if versions.is_empty() {
match self
.ensure_latest_inner(binary, true, progress_tracker)
.await
{
Ok(version) => {
self.latest_versions
.write()
.await
.insert(binary, version.clone());
return Ok(version);
}
Err(e) => {
return Err(e);
match self.adapters.get(&binary) {
Some(adapter) => {
let bin_folder = adapter.get_binary_folder();
match std::fs::read_dir(&bin_folder) {
Ok(version_folders_list) => {
// Search for all valid versions of the binary
let mut versions = vec![];
for entry in version_folders_list {
let entry = match entry {
Ok(entry) => entry,
Err(e) => {
error!(target:LOG_TARGET, "Failed to unwrap DirEntry: {}", e);
continue;
}
};
let path = entry.path();
if path.is_dir() {
// Check for actual binary existing. It can happen that the folder is there,
// for in_progress downloads or perhaps the antivirus has quarantined the file
let mut executable_name = match get_binary_name(
binary,
path.clone(),
) {
Ok(name) => name,
Err(e) => {
error!(target: LOG_TARGET, "Failed to get binary name: {:?}", e);
continue;
}
};

if cfg!(target_os = "windows") {
executable_name = executable_name.with_extension("exe");
}
if !executable_name.exists() {
continue;
}

let version = path.file_name().unwrap().to_str().unwrap();
versions.push(Version::parse(version).unwrap());
}
}

if !versions.is_empty() {
versions.sort();
let cached_version = versions.pop().unwrap();
let current_version = self.get_latest_version(binary).await;
let highest_version = cached_version.max(current_version);

self.latest_versions
.write()
.await
.insert(binary, highest_version.clone());

return Ok(highest_version.clone());
}
}
Err(_) => match std::fs::create_dir_all(&bin_folder) {
Ok(_) => info!(target:LOG_TARGET, "Created bin dir: {:?}", bin_folder),
Err(e) => error!(target:LOG_TARGET, "Failed to create dir: {}", e),
},
}
}
None => return Err(anyhow!("No latest version adapter for this binary")),
}

versions.sort();
let cached_version = versions.pop().unwrap();
let current_version = self.get_latest_version(binary).await;

let highest_version = cached_version.max(current_version);

// If no local versions were found, download the latest version
let version = self
.ensure_latest_inner(binary, true, progress_tracker)
.await?;
self.latest_versions
.write()
.await
.insert(binary, highest_version.clone());

Ok(highest_version.clone())
.insert(binary, version.clone());
Ok(version)
}

pub async fn get_latest_version(&self, binary: Binaries) -> Version {
Expand Down
Loading
Loading