Skip to content

fix: searching for env and config files in wrong directories#325

Closed
pauldelucia wants to merge 2 commits into
masterfrom
fix/directory-searching
Closed

fix: searching for env and config files in wrong directories#325
pauldelucia wants to merge 2 commits into
masterfrom
fix/directory-searching

Conversation

@pauldelucia
Copy link
Copy Markdown
Member

@pauldelucia pauldelucia commented Jun 5, 2025

Summary by CodeRabbit

  • New Features

    • Improved detection and copying of environment files, prioritizing the executable's directory before falling back to the current working directory.
    • Enhanced logic for locating the Dash configuration file, preferring the executable's directory for greater reliability.
  • Style

    • Reformatted code for improved readability, including multi-line function signatures and argument lists.
    • Removed trailing whitespace in the user interface code.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 5, 2025

Walkthrough

The changes update the logic for locating and copying environment and configuration files, now prioritizing the executable's directory before the current working directory. Several function calls are reformatted for improved readability, and minor whitespace cleanups are performed. No public API signatures are changed, and no new features are introduced.

Changes

File(s) Change Summary
src/app_dir.rs Refactored import order, reformatted function signature, and enhanced .env file search logic to prioritize executable directory.
src/backend_task/core/mod.rs, src/context.rs Reformatted multi-line function calls for readability; no logic changes.
src/backend_task/core/start_dash_qt.rs Changed config file path resolution to prefer executable directory over current working directory.
src/ui/identities/add_existing_identity_screen.rs Removed trailing whitespace from specific code blocks.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant FileSystem

    User->>App: Start application
    App->>FileSystem: Check for .env.example or .env in executable dir
    alt Found in executable dir
        FileSystem-->>App: Return path to found file
        App->>FileSystem: Copy file to app data directory
    else Not found in executable dir
        App->>FileSystem: Check for .env.example or .env in current working dir
        alt Found in current working dir
            FileSystem-->>App: Return path to found file
            App->>FileSystem: Copy file to app data directory
        else Not found
            FileSystem-->>App: No file found
        end
    end
Loading

Possibly related PRs

  • feat: application data directory #22: Adds initial logic for copying environment files to the application data directory, which is extended in this PR by prioritizing the executable directory.

Suggested reviewers

  • PastaPastaPasta
  • QuantumExplorer

Poem

In the warren where configs hide,
The bunny hops from side to side.
First the exe’s den it’ll search,
If not, the working dir’s its perch.
With tidy code and paths anew,
This rabbit brings fresh order through!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b3dd763 and 147964d.

📒 Files selected for processing (1)
  • src/app_dir.rs (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/app_dir.rs
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Build and Release Dash Evo Tool (Windows, ubuntu-24.04, x86_64-pc-windows-gnu, windows, .exe)
  • GitHub Check: Build and Release Dash Evo Tool (macos-x86_64, macos-13, x86_64-apple-darwin, x86_64-mac)
  • GitHub Check: Build and Release Dash Evo Tool (linux-x86_64, ubuntu-24.04, x86_64-unknown-linux-gnu, x86_64-linux)
  • GitHub Check: Build and Release Dash Evo Tool (macos-arm64, macos-latest, aarch64-apple-darwin, arm64-mac)
  • GitHub Check: Build and Release Dash Evo Tool (linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, arm64-...
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/app_dir.rs (1)

93-125: Excellent fix for the file location logic

This change properly addresses the PR objective by prioritizing the executable directory over the current working directory when searching for environment files. The logic is sound:

  1. First checks executable directory for .env.example
  2. Falls back to executable directory for .env
  3. Then checks current working directory for .env.example
  4. Finally checks current working directory for .env (with proper existence validation)

This approach is much more reliable for deployed applications where configuration files should be co-located with the executable.

Consider improving error handling consistency:

- fs::copy(&env_example_file_in_exe_dir, env_file_in_app_dir)
-     .expect("Failed to copy env file");
+ fs::copy(&env_example_file_in_exe_dir, &env_file_in_app_dir)
+     .expect("Failed to copy .env.example file from executable directory");

Similar improvements could be made to the other copy operations for more specific error messages.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 15ad443 and b3dd763.

📒 Files selected for processing (5)
  • src/app_dir.rs (3 hunks)
  • src/backend_task/core/mod.rs (1 hunks)
  • src/backend_task/core/start_dash_qt.rs (1 hunks)
  • src/context.rs (2 hunks)
  • src/ui/identities/add_existing_identity_screen.rs (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
src/backend_task/core/start_dash_qt.rs (1)
Learnt from: ogabrielides
PR: dashpay/dash-evo-tool#73
File: src/backend_task/core/start_dash_qt.rs:17-18
Timestamp: 2024-11-18T14:40:33.353Z
Learning: In `src/backend_task/core/start_dash_qt.rs`, the `start_dash_qt` function verifies the existence of `dash_qt_path` using `dash_qt_path.exists()`, which the team considers sufficient validation for `custom_dash_qt` provided by the user.
🧬 Code Graph Analysis (1)
src/context.rs (1)
src/app_dir.rs (1)
  • core_cookie_path (46-60)
🔇 Additional comments (7)
src/backend_task/core/mod.rs (1)

60-63: LGTM: Improved readability

The multi-line formatting makes the function call more readable and aligns with similar formatting improvements throughout the codebase.

src/ui/identities/add_existing_identity_screen.rs (1)

192-193: LGTM: Good code hygiene

Removing trailing whitespace improves code quality and consistency. These changes align well with the overall cleanup theme of this PR.

Also applies to: 227-227, 234-234, 247-247, 252-252, 255-255

src/app_dir.rs (2)

1-2: LGTM: Improved import organization

The import reordering improves code organization and readability.


46-49: LGTM: Better function signature formatting

The multi-line formatting improves readability and is consistent with similar improvements throughout the codebase.

src/context.rs (2)

90-91: LGTM: Improved readability

Splitting the function call and expect clause across multiple lines improves code readability and makes the error handling more prominent.


110-111: LGTM: Consistent formatting improvement

The multi-line formatting for the expect clause is consistent with the similar change above and improves readability.

src/backend_task/core/start_dash_qt.rs (1)

56-67: LGTM! Improved config file location logic.

The updated logic to prioritize the executable's directory over the current working directory is a solid improvement for config file discovery. This approach is more robust, especially when the application is run from different locations or when deployed as a bundled executable.

The error handling with proper fallbacks to the current working directory ensures backward compatibility while making the file location more reliable.

Comment thread src/app_dir.rs
let env_file_in_app_dir = app_data_dir.join(".env".to_string());
if !env_file_in_app_dir.exists() || !env_file_in_app_dir.is_file() {
// Get the directory where the executable is located
let exe_dir = std::env::current_exe()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to embed the default .env file inside the binary. Looks like include_bytes! can do the job, but I didn't test this.

@pauldelucia pauldelucia changed the base branch from master to v0.9-dev June 5, 2025 09:14
@pauldelucia pauldelucia changed the base branch from v0.9-dev to master June 5, 2025 09:15
@pauldelucia pauldelucia closed this Jun 5, 2025
@pauldelucia pauldelucia deleted the fix/directory-searching branch June 5, 2025 10:45
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.

2 participants