(dc: &mut DoctorCounters, gdb: &crate::global_db::GlobalDb)
| 309 | } |
| 310 | |
| 311 | async fn check_stale_code_projects(dc: &mut DoctorCounters, gdb: &crate::global_db::GlobalDb) { |
| 312 | use std::io::{IsTerminal, Write}; |
| 313 | |
| 314 | let stale: Vec<_> = gdb |
| 315 | .list_code_projects(usize::MAX) |
| 316 | .await |
| 317 | .into_iter() |
| 318 | .filter(|project| !code_project_root_exists(project)) |
| 319 | .collect(); |
| 320 | |
| 321 | if stale.is_empty() { |
| 322 | dc.pass("No stale code project registry rows"); |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | dc.warn(&format!( |
| 327 | "{} stale code project registry row(s) (registered but project root is gone):", |
| 328 | stale.len() |
| 329 | )); |
| 330 | let preview = stale.len().min(10); |
| 331 | for project in &stale[..preview] { |
| 332 | dc.info(&format!( |
| 333 | " • {} ({})", |
| 334 | project.project_id, project.display_root |
| 335 | )); |
| 336 | } |
| 337 | if stale.len() > preview { |
| 338 | dc.info(&format!(" … and {} more", stale.len() - preview)); |
| 339 | } |
| 340 | |
| 341 | if !std::io::stdin().is_terminal() { |
| 342 | dc.info(" Re-run `tracedecay doctor` interactively to purge registry rows."); |
| 343 | return; |
| 344 | } |
| 345 | |
| 346 | eprint!( |
| 347 | " Purge {} stale code project registry row(s)? [Y/n] ", |
| 348 | stale.len() |
| 349 | ); |
| 350 | std::io::stderr().flush().ok(); |
| 351 | let mut answer = String::new(); |
| 352 | if std::io::stdin().read_line(&mut answer).is_err() { |
| 353 | return; |
| 354 | } |
| 355 | let answer = answer.trim(); |
| 356 | if !answer.is_empty() && !answer.eq_ignore_ascii_case("y") { |
| 357 | dc.info("Skipped code project registry purge."); |
| 358 | return; |
| 359 | } |
| 360 | |
| 361 | let project_ids: Vec<String> = stale |
| 362 | .into_iter() |
| 363 | .map(|project| project.project_id) |
| 364 | .collect(); |
| 365 | let purged = gdb.delete_code_projects(&project_ids).await; |
| 366 | dc.pass(&format!( |
| 367 | "Purged {purged} stale code project registry row(s)" |
| 368 | )); |
no test coverage detected