|
49 | 49 | ENV_FILE = STATE_DIR / ".env" |
50 | 50 | LOG_FILE = STATE_DIR / "ezlocalai.log" |
51 | 51 | PID_FILE = STATE_DIR / "ezlocalai.pid" |
| 52 | +SOURCE_DIR_FILE = STATE_DIR / "source_dir" |
52 | 53 | REPO_URL = "https://github.com/DevXT-LLC/ezlocalai.git" |
53 | 54 | REPO_DIR = STATE_DIR / "repo" |
54 | 55 |
|
@@ -531,14 +532,33 @@ def is_ezlocalai_folder(folder: Path) -> bool: |
531 | 532 |
|
532 | 533 |
|
533 | 534 | def get_ezlocalai_source_dir() -> Optional[Path]: |
534 | | - """Get the ezlocalai source directory if running from within it. |
| 535 | + """Get the ezlocalai source directory. |
535 | 536 |
|
536 | | - Returns the current working directory if it's the ezlocalai folder, |
537 | | - otherwise returns None. |
| 537 | + Checks (in order): |
| 538 | + 1. Current working directory (if it's the ezlocalai folder) |
| 539 | + 2. Persisted source directory from ~/.ezlocalai/source_dir |
| 540 | +
|
| 541 | + When found via cwd, the path is persisted so future invocations |
| 542 | + from other directories still find the source .env and compose files. |
538 | 543 | """ |
539 | 544 | cwd = Path.cwd() |
540 | 545 | if is_ezlocalai_folder(cwd): |
| 546 | + # Persist for future use from other directories |
| 547 | + try: |
| 548 | + SOURCE_DIR_FILE.write_text(str(cwd), encoding="utf-8") |
| 549 | + except OSError: |
| 550 | + pass |
541 | 551 | return cwd |
| 552 | + |
| 553 | + # Check persisted path |
| 554 | + if SOURCE_DIR_FILE.exists(): |
| 555 | + try: |
| 556 | + saved = Path(SOURCE_DIR_FILE.read_text(encoding="utf-8").strip()) |
| 557 | + if saved.exists() and is_ezlocalai_folder(saved): |
| 558 | + return saved |
| 559 | + except (OSError, ValueError): |
| 560 | + pass |
| 561 | + |
542 | 562 | return None |
543 | 563 |
|
544 | 564 |
|
|
0 commit comments