Skip to content

fix(app): fall back to default data folder when persisted path is stale - #8855

Open
santhiprakash wants to merge 1 commit into
janhq:mainfrom
santhiprakash:fix/jan-data-folder-rename-fallback
Open

fix(app): fall back to default data folder when persisted path is stale#8855
santhiprakash wants to merge 1 commit into
janhq:mainfrom
santhiprakash:fix/jan-data-folder-rename-fallback

Conversation

@santhiprakash

Copy link
Copy Markdown

Describe Your Changes

  • Fix resolve_jan_data_folder() (CLI/headless path) and get_app_configurations() (Tauri app path) so a persisted data_folder that no longer exists or is unreadable falls back to the default Jan data folder instead of returning the stale path.
  • Add is_readable_data_folder() and default_data_folder_path_internal() helpers in src-tauri/src/core/app/commands.rs.
  • Add regression tests covering both the CLI path (resolve_jan_data_folder) and the app path (get_app_configurations).
  • Keep the JAN_DATA_FOLDER environment override as an explicit opt-in that is not validated or fallen back from.

Fixes Issues

Self Checklist

  • Added regression tests for stale data_folder fallback
  • Ran cargo fmt -- src/core/app/commands.rs and cargo fmt --check -- src/core/app/commands.rs (clean)
  • Ran cargo clippy --lib (clean)
  • Ran cargo test --lib core::app::commands

Problem

After a macOS user home folder is renamed, settings.json still contains the old absolute data_folder (e.g. /Users/<oldname>/Library/Application Support/Jan/data). Both resolve_jan_data_folder() and get_app_configurations() returned that path directly, so the app started against a non-existent directory and crashed.

Triage

  • resolve_jan_data_folder() parsed config.data_folder and returned it with no existence/readability check.
  • get_app_configurations() parsed the file and returned the stored data_folder without validating it.

Fix

Both read paths now call is_readable_data_folder() on the persisted data_folder. If it is missing or unreadable, they log a warning and fall back to the default Jan data folder. The JAN_DATA_FOLDER environment override still takes precedence and is not validated.

Verification

Before the fix, a stale absolute data_folder returned the stale path:

thread 'core::app::commands::tests::resolve_jan_data_folder_falls_back_when_stale' panicked at src/core/app/commands.rs:491:9:
assertion `left == right` failed
  left: "/tmp/.../stale_home/Library/Application Support/Jan/data"
 right: "/tmp/.../Jan/data"

After the fix, both new tests and the existing command tests pass:

$ cd src-tauri && cargo test --lib core::app::commands
running 6 tests
test core::app::commands::tests::bundle_identifier_matches_tauri_conf ... ok
test core::app::commands::tests::migration_handles_missing_legacy_files ... ok
test core::app::commands::tests::migration_skips_when_canonical_exists ... ok
test core::app::commands::tests::migration_recovers_legacy_then_removes_stale_copy ... ok
test core::app::commands::tests::resolve_jan_data_folder_falls_back_when_stale ... ok
test core::app::commands::tests::get_app_configurations_falls_back_when_stale ... ok

test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 664 filtered out
$ cd src-tauri && cargo clippy --lib
    Checking Jan v0.8.4 (/mnt/data/open-source/jan/src-tauri)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 5.76s

Formatter: cargo fmt -- src/core/app/commands.rs followed by cargo fmt --check -- src/core/app/commands.rs returned no diff.

Notes

  • This is a runtime fallback; it intentionally does not rewrite settings.json on disk. The optional companion change to persist a tilde-based default path is left for a separate commit/PR as suggested in the issue.
  • The new tests take an ENV_TEST_LOCK because they redirect XDG_DATA_HOME / XDG_CONFIG_HOME / HOME (for the CLI test) and APP_NAME (for the Tauri test) while running in parallel with other tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

bug: App crash after home folder name change

1 participant