Skip to content

Commit 761285b

Browse files
committed
Validate home setup after applying configs
1 parent bfe9ff7 commit 761285b

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

src/home.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ pub fn run(opts: HomeOpts) -> Result<()> {
103103
}
104104
}
105105
ensure_kar_repo(&flow_bin, prefer_ssh)?;
106+
validate_setup(&config_dir)?;
106107

107108
if !archived.is_empty() {
108109
println!("\nMoved existing config files to ~/flow-archive:");
@@ -385,6 +386,63 @@ fn ensure_kar_repo(flow_bin: &Path, prefer_ssh: bool) -> Result<()> {
385386
Ok(())
386387
}
387388

389+
fn validate_setup(config_dir: &Path) -> Result<()> {
390+
let home = dirs::home_dir().context("Could not find home directory")?;
391+
let mappings = load_link_mappings(config_dir)?;
392+
let mut missing = Vec::new();
393+
let mut mismatched = Vec::new();
394+
395+
for (source_rel, dest_rel) in &mappings {
396+
let source = config_dir.join(source_rel);
397+
if !source.exists() {
398+
continue;
399+
}
400+
401+
let dest_rel = normalize_dest_rel(dest_rel)?;
402+
let dest = home.join(&dest_rel);
403+
if !dest.exists() {
404+
missing.push(dest);
405+
continue;
406+
}
407+
408+
if !is_symlink_to(&dest, &source) {
409+
mismatched.push((dest, source));
410+
}
411+
}
412+
413+
let mut critical_missing = Vec::new();
414+
let kar_config = home.join(".config/kar/config.ts");
415+
if !kar_config.exists() {
416+
critical_missing.push(kar_config);
417+
}
418+
let karabiner_config = home.join(".config/karabiner.edn");
419+
if !karabiner_config.exists() {
420+
critical_missing.push(karabiner_config);
421+
}
422+
423+
if missing.is_empty() && mismatched.is_empty() && critical_missing.is_empty() {
424+
println!("Validation: all expected configs are in place.");
425+
return Ok(());
426+
}
427+
428+
println!("\nValidation warnings:");
429+
for path in critical_missing {
430+
println!(" missing critical config: {}", path.display());
431+
}
432+
for path in missing {
433+
println!(" missing link target: {}", path.display());
434+
}
435+
for (dest, source) in mismatched {
436+
println!(
437+
" not linked: {} (expected -> {})",
438+
dest.display(),
439+
source.display()
440+
);
441+
}
442+
443+
Ok(())
444+
}
445+
388446
fn ensure_repo(
389447
dest: &Path,
390448
repo_url: Option<&str>,

0 commit comments

Comments
 (0)