Create symlinks for shared agent data files from the current (worktree) data directory to the canonical dev data directory. Guards: - `BUZZ_SHARE_IDENTITY` must be `"1"` - `BUZZ_PRIVATE_KEY` must parse as valid `nostr::Keys` - The canonical dir must differ from the current dir (skip if we ARE canonical) - The canonical dir must exist
(app: &tauri::AppHandle)
| 471 | /// - The canonical dir must differ from the current dir (skip if we ARE canonical) |
| 472 | /// - The canonical dir must exist |
| 473 | pub fn sync_shared_agent_data(app: &tauri::AppHandle) { |
| 474 | // Guard: only runs when sharing identity with a worktree. |
| 475 | let is_shared = std::env::var("BUZZ_SHARE_IDENTITY") |
| 476 | .map(|v| v == "1") |
| 477 | .unwrap_or(false); |
| 478 | if !is_shared { |
| 479 | return; |
| 480 | } |
| 481 | |
| 482 | // Guard: BUZZ_PRIVATE_KEY must be a valid nostr key. |
| 483 | let has_valid_key = std::env::var("BUZZ_PRIVATE_KEY") |
| 484 | .ok() |
| 485 | .and_then(|k| k.parse::<nostr::Keys>().ok()) |
| 486 | .is_some(); |
| 487 | if !has_valid_key { |
| 488 | eprintln!("buzz-desktop: shared-agent-sync: BUZZ_PRIVATE_KEY missing or invalid, skipping"); |
| 489 | return; |
| 490 | } |
| 491 | |
| 492 | let current_dir = match app.path().app_data_dir() { |
| 493 | Ok(dir) => dir, |
| 494 | Err(e) => { |
| 495 | eprintln!("buzz-desktop: shared-agent-sync: cannot resolve app data dir: {e}"); |
| 496 | return; |
| 497 | } |
| 498 | }; |
| 499 | |
| 500 | let canonical_dir = match canonical_dev_data_dir(¤t_dir) { |
| 501 | Some(dir) => dir, |
| 502 | None => { |
| 503 | eprintln!("buzz-desktop: shared-agent-sync: cannot compute canonical dir (no parent)"); |
| 504 | return; |
| 505 | } |
| 506 | }; |
| 507 | |
| 508 | // Guard: skip if we ARE the canonical instance. |
| 509 | // Use canonicalize to handle case-insensitive FS and symlinks. |
| 510 | let current_canonical = |
| 511 | std::fs::canonicalize(¤t_dir).unwrap_or_else(|_| current_dir.clone()); |
| 512 | let source_canonical = |
| 513 | std::fs::canonicalize(&canonical_dir).unwrap_or_else(|_| canonical_dir.clone()); |
| 514 | if current_canonical == source_canonical { |
| 515 | return; |
| 516 | } |
| 517 | |
| 518 | // Guard: skip if canonical dir doesn't exist. |
| 519 | if !canonical_dir.exists() { |
| 520 | eprintln!( |
| 521 | "buzz-desktop: shared-agent-sync: canonical dir does not exist: {}", |
| 522 | canonical_dir.display() |
| 523 | ); |
| 524 | return; |
| 525 | } |
| 526 | |
| 527 | // Seed-up: if canonical is missing a shared file but a sibling instance |
| 528 | // holds real (non-symlink) content, migrate it up to canonical before the |
| 529 | // symlink loop runs. Mirrors the SHARED_AGENT_DIRS migration below, applied |
| 530 | // to individual files. Without this, a fresh write in a worktree is never |
no test coverage detected