chore: linting

This commit is contained in:
zhom
2025-07-27 03:09:22 +04:00
parent ff9c633b07
commit adcb20fab9
4 changed files with 43 additions and 32 deletions
+2 -1
View File
@@ -1642,7 +1642,8 @@ impl BrowserRunner {
let binaries_dir = self.get_binaries_dir();
// Use comprehensive cleanup that syncs registry with disk and removes unused binaries
let cleaned_up = registry.comprehensive_cleanup(&binaries_dir, &active_versions, &running_versions)?;
let cleaned_up =
registry.comprehensive_cleanup(&binaries_dir, &active_versions, &running_versions)?;
// Registry is already saved by comprehensive_cleanup
Ok(cleaned_up)
+22 -18
View File
@@ -267,7 +267,7 @@ impl DownloadedBrowsersRegistry {
binaries_dir: &std::path::Path,
) -> Result<Vec<String>, Box<dyn std::error::Error + Send + Sync>> {
let mut changes = Vec::new();
if !binaries_dir.exists() {
return Ok(changes);
}
@@ -276,15 +276,16 @@ impl DownloadedBrowsersRegistry {
for browser_entry in fs::read_dir(binaries_dir)? {
let browser_entry = browser_entry?;
let browser_path = browser_entry.path();
if !browser_path.is_dir() {
continue;
}
let browser_name = browser_path.file_name()
let browser_name = browser_path
.file_name()
.and_then(|n| n.to_str())
.unwrap_or("");
if browser_name.is_empty() || browser_name.starts_with('.') {
continue;
}
@@ -293,15 +294,16 @@ impl DownloadedBrowsersRegistry {
for version_entry in fs::read_dir(&browser_path)? {
let version_entry = version_entry?;
let version_path = version_entry.path();
if !version_path.is_dir() {
continue;
}
let version_name = version_path.file_name()
let version_name = version_path
.file_name()
.and_then(|n| n.to_str())
.unwrap_or("");
if version_name.is_empty() || version_name.starts_with('.') {
continue;
}
@@ -319,11 +321,11 @@ impl DownloadedBrowsersRegistry {
}
}
}
if !changes.is_empty() {
self.save()?;
}
Ok(changes)
}
@@ -335,23 +337,23 @@ impl DownloadedBrowsersRegistry {
running_profiles: &[(String, String)],
) -> Result<Vec<String>, Box<dyn std::error::Error + Send + Sync>> {
let mut cleanup_results = Vec::new();
// First, sync registry with actual binaries on disk
let sync_results = self.sync_with_binaries_directory(binaries_dir)?;
cleanup_results.extend(sync_results);
// Then perform the regular cleanup
let regular_cleanup = self.cleanup_unused_binaries(active_profiles, running_profiles)?;
cleanup_results.extend(regular_cleanup);
// Finally, verify and cleanup stale entries
let stale_cleanup = self.verify_and_cleanup_stale_entries_simple(binaries_dir)?;
cleanup_results.extend(stale_cleanup);
if !cleanup_results.is_empty() {
self.save()?;
}
Ok(cleanup_results)
}
@@ -364,7 +366,7 @@ impl DownloadedBrowsersRegistry {
let mut browsers_to_remove = Vec::new();
for (browser_str, versions) in &self.browsers {
for (version, _info) in versions {
for version in versions.keys() {
// Check if the browser directory actually exists
let browser_dir = binaries_dir.join(browser_str).join(version);
if !browser_dir.exists() {
@@ -376,7 +378,9 @@ impl DownloadedBrowsersRegistry {
// Remove stale entries
for (browser_str, version) in browsers_to_remove {
if let Some(_removed) = self.remove_browser(&browser_str, &version) {
cleaned_up.push(format!("Removed stale registry entry for {browser_str} {version}"));
cleaned_up.push(format!(
"Removed stale registry entry for {browser_str} {version}"
));
}
}
+19 -11
View File
@@ -31,13 +31,12 @@ mod version_updater;
extern crate lazy_static;
use browser_runner::{
check_browser_exists, check_browser_status, check_missing_binaries,
create_browser_profile_new, delete_profile, download_browser, ensure_all_binaries_exist,
fetch_browser_versions_cached_first, fetch_browser_versions_with_count,
fetch_browser_versions_with_count_cached_first, get_browser_release_types,
get_downloaded_browser_versions, get_supported_browsers, is_browser_supported_on_platform,
kill_browser_profile, launch_browser_profile, list_browser_profiles, rename_profile,
update_profile_proxy, update_profile_version,
check_browser_exists, check_browser_status, check_missing_binaries, create_browser_profile_new,
delete_profile, download_browser, ensure_all_binaries_exist, fetch_browser_versions_cached_first,
fetch_browser_versions_with_count, fetch_browser_versions_with_count_cached_first,
get_browser_release_types, get_downloaded_browser_versions, get_supported_browsers,
is_browser_supported_on_platform, kill_browser_profile, launch_browser_profile,
list_browser_profiles, rename_profile, update_profile_proxy, update_profile_version,
};
use settings_manager::{
@@ -409,7 +408,7 @@ pub fn run() {
tauri::async_runtime::spawn(async move {
println!("Starting nodecar warm-up...");
let start_time = std::time::Instant::now();
// Send a ping request to nodecar to trigger unpacking/warm-up
match tokio::process::Command::new("nodecar")
.arg("--version")
@@ -419,14 +418,23 @@ pub fn run() {
Ok(output) => {
let duration = start_time.elapsed();
if output.status.success() {
println!("Nodecar warm-up completed successfully in {:.2}s", duration.as_secs_f64());
println!(
"Nodecar warm-up completed successfully in {:.2}s",
duration.as_secs_f64()
);
} else {
println!("Nodecar warm-up completed with non-zero exit code in {:.2}s", duration.as_secs_f64());
println!(
"Nodecar warm-up completed with non-zero exit code in {:.2}s",
duration.as_secs_f64()
);
}
}
Err(e) => {
let duration = start_time.elapsed();
println!("Nodecar warm-up failed after {:.2}s: {e}", duration.as_secs_f64());
println!(
"Nodecar warm-up failed after {:.2}s: {e}",
duration.as_secs_f64()
);
}
}
});
-2
View File
@@ -780,9 +780,7 @@ mod tests {
.arg("--type")
.arg("http");
let start_time = std::time::Instant::now();
let output = tokio::time::timeout(Duration::from_secs(60), async { cmd.output() }).await??;
let execution_time = start_time.elapsed();
if output.status.success() {
let stdout = String::from_utf8(output.stdout)?;