Skip to content
Open
Changes from 2 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
42 changes: 41 additions & 1 deletion src/component/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub async fn run_doctor_checks() -> Result<()> {
check_config_files(&mut check);
check_dependencies(&mut check);
check_network_connectivity(&mut check).await;
check_installed_binaries(&mut check);

println!("\n{}", "Checkup complete.".bold());
if errors > 0 {
Expand Down Expand Up @@ -236,6 +237,43 @@ async fn check_network_connectivity(check: &mut impl FnMut(&str, Result<String,
}
}

fn check_installed_binaries(check: &mut impl FnMut(&str, Result<String, String>)) {
match InstalledBinaries::read_from_file() {
Ok(binaries) => {
let mut valid_count = 0;
let mut invalid_count = 0;

for binary in binaries.binaries() {
let binary_path = get_default_bin_dir().join(&binary.binary_name);
if binary_path.exists() && binary_path.is_file() {
valid_count += 1;
} else {
invalid_count += 1;
}
}

if invalid_count == 0 {
check(
"Installed binaries",
Ok(format!("All {} binaries are valid", valid_count)),
);
} else {
check(
"Installed binaries",
Err(format!(
"WARN: {} valid, {} invalid binaries found",
valid_count, invalid_count
)),
Comment thread
luojiyin1987 marked this conversation as resolved.
);
}
}
Err(_) => check(
"Installed binaries",
Ok("No binaries installed yet".to_string()),
),
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -307,7 +345,9 @@ mod tests {
println!("Path exists: {}", path.exists());
let result = check_suiup_data_dir();
assert!(result.is_err());
assert!(result.unwrap_err().contains("suiup data directory not found"));
assert!(result
.unwrap_err()
.contains("suiup data directory not found"));

// Restore original env var
#[cfg(windows)]
Expand Down
Loading