Skip to content

feat: honor FOREST_PATH env var for data directory#7215

Closed
0xDevNinja wants to merge 2 commits into
ChainSafe:mainfrom
0xDevNinja:feat/issue-6008-forest-path-env
Closed

feat: honor FOREST_PATH env var for data directory#7215
0xDevNinja wants to merge 2 commits into
ChainSafe:mainfrom
0xDevNinja:feat/issue-6008-forest-path-env

Conversation

@0xDevNinja

@0xDevNinja 0xDevNinja commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Summary of changes

Reopens the work from #7080, which was closed as stale. Rebased on current main and the only review feedback (a CodeRabbit nit) is addressed.

Changes introduced in this pull request:

  • Add a FOREST_PATH environment variable that overrides the data directory for forest, forest-cli, forest-tool and forest-wallet.
  • Precedence is env > config > defaults — when set, FOREST_PATH wins over client.data_dir from the config file; when unset, behavior is unchanged.
  • forest-wallet honors FOREST_PATH when set, otherwise keeps the existing Forest-Wallet ProjectDirs location for backwards compatibility.
  • Daemon logs the resolved data directory on startup (per the issue follow-up comment).
  • Docs entry in env_variables.md and a CHANGELOG.md entry.

Reference issue to close (if applicable)

Closes #6008

Other information and links

Mirrors Lotus's LOTUS_PATH so operators switching between implementations get a consistent escape hatch. The wallet override is intentionally opt-in (no implicit migration of the existing Forest-Wallet ProjectDirs location).

Tests: read_config_forest_path_env_override exercises env-over-config precedence (gated by serial_test::serial). Following the review on #7080, the test now uses a drop guard that restores any pre-existing FOREST_PATH value and runs cleanup even on panic, instead of unconditionally unsetting the variable. Added forest_path_from_env_empty_is_none and forest_path_from_env_unset_is_none to cover the empty-string and unset cases.

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Summary by CodeRabbit

  • New Features

    • Added FOREST_PATH environment variable to override the data directory for Forest, Forest CLI, Forest Tool, and Forest Wallet. Takes precedence over client.data_dir in the config file.
  • Documentation

    • Updated environment variables reference guide with FOREST_PATH documentation.
  • Improvements

    • Data directory location is now logged on startup.

Adds a FOREST_PATH environment variable that overrides
`client.data_dir` for `forest`, `forest-cli`, `forest-tool` and
`forest-wallet`. Precedence is env > config > defaults. The daemon
also logs the resolved data directory on startup.

Closes ChainSafe#6008
Add a drop guard so the env-override test restores any prior
FOREST_PATH value (and runs cleanup on panic) instead of
unconditionally unsetting it. Add unit tests covering the
empty-string and unset cases of forest_path_from_env.
@0xDevNinja 0xDevNinja requested a review from a team as a code owner June 22, 2026 09:53
@0xDevNinja 0xDevNinja requested review from hanabi1224 and sudo-shashank and removed request for a team June 22, 2026 09:53
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 775920ff-c2b2-4575-8a9a-6bd65aa34c4b

📥 Commits

Reviewing files that changed from the base of the PR and between 9aa6f70 and 905f51a.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • docs/docs/users/reference/env_variables.md
  • src/cli_shared/mod.rs
  • src/daemon/mod.rs
  • src/wallet/subcommands/wallet_cmd.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • filecoin-project/lotus (manual)

Walkthrough

Introduces a FOREST_PATH environment variable that overrides the Forest data directory. A new constant and helper function read the env var; read_config() applies the override to config.client.data_dir. WalletBackend::new_local and the daemon startup also respect or log the resolved path. Tests and documentation are included.

Changes

FOREST_PATH environment variable support

Layer / File(s) Summary
FOREST_PATH_ENV constant, helper, and read_config() integration
src/cli_shared/mod.rs
Adds pub const FOREST_PATH_ENV and pub fn forest_path_from_env() returning Some(PathBuf) for non-empty values; read_config() replaces config.client.data_dir with the env-provided path when present.
Wallet and daemon integration
src/wallet/subcommands/wallet_cmd.rs, src/daemon/mod.rs
WalletBackend::new_local conditionally resolves wallet_dir from forest_path_from_env() instead of unconditionally using ProjectDirs; daemon startup_init logs config.client.data_dir via info!.
EnvGuard and env override tests
src/cli_shared/mod.rs
Adds EnvGuard struct with Drop impl for safe env var restoration, plus three #[serial_test::serial] tests covering the read_config() override, empty-string, and unset FOREST_PATH cases.
Documentation and changelog
docs/docs/users/reference/env_variables.md, CHANGELOG.md
Adds FOREST_PATH row to the env variables reference table and a changelog bullet describing its precedence over client.data_dir and startup logging.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • hanabi1224
  • sudo-shashank
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main feature added: introducing the FOREST_PATH environment variable for data directory customization.
Linked Issues check ✅ Passed The PR implements all coding requirements from #6008: introduces FOREST_PATH environment variable with correct precedence (env > config > defaults), updates documentation in env_variables.md, adds CHANGELOG.md entry, implements override behavior across forest/forest-cli/forest-tool/forest-wallet binaries, and includes comprehensive test coverage.
Out of Scope Changes check ✅ Passed All changes directly support the FOREST_PATH feature: documentation updates, CHANGELOG entry, environment variable handling, config loading modifications, and test infrastructure are all within scope of implementing the environment variable override requirement.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch feat/issue-6008-forest-path-env
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@LesnyRumcajs

Copy link
Copy Markdown
Member

@0xDevNinja this is already being resolved via #7200.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Customize Forest data directory via env variable

2 participants