Skip to content

[FEAT] Add cross-platform support (Windows) for configuration and storage paths #22

Description

@daniil-verba

[FEAT] Add cross-platform support (Windows) for configuration and storage paths

📝 Description

Currently, the project's storage and configuration logic (e.g., in storage/*.rs) is hardcoded to follow Linux filesystem standards (like ~/.config/undertow). As a result, the protocol fails to start or save data correctly on Windows environments.

This issue aims to refactor the path resolution logic to be fully cross-platform, with immediate focus on adding robust Windows support.

💡 Motivation

  • Expand User Base: A P2P protocol should be usable by anyone, regardless of their OS. Currently, Windows users cannot use undertow-protocol.
  • Developer Experience: Many contributors and testers primarily use Windows. Making the project build and run out-of-the-box on Windows will lower the barrier to entry for new contributors.
  • Prevent Panics: Prevents runtime errors/panics when the application tries to access non-existent Linux paths on a Windows machine.

⚙️ Technical Details

Instead of manually concatenating strings or relying on std::env::var("HOME"), we should use an established, cross-platform crate to resolve standard directories.

Implementation Steps:

  1. Add Dependency: Add the directories (or dirs) crate to Cargo.toml.
  2. Refactor storage/*.rs: Replace hardcoded Linux paths with OS-aware path resolution.
    Example:
    use directories::ProjectDirs;
    
    // This resolves to:
    // Linux: ~/.config/undertow-protocol
    // Windows: C:\Users\Username\AppData\Roaming\undertow-protocol
    // macOS: ~/Library/Application Support/undertow-protocol
    let proj_dirs = ProjectDirs::from("com", "undertow", "protocol").unwrap();
    let config_dir = proj_dirs.config_dir();
  3. Testing: Verify that the application successfully creates the directory and reads/writes config files on a Windows machine (or via cross-compilation check: cargo check --target x86_64-pc-windows-msvc).

🔄 Alternatives Considered

  • Manual #[cfg(target_os = "...")] macros: Writing custom if/else blocks for every OS. Rejected: Reinvents the wheel, prone to edge-case bugs, and harder to maintain if we add macOS support later.
  • Using the Current Working Directory (./config.json): Rejected: This is bad practice for background services or libraries, as it clutters the user's execution directory and depends on where the binary was launched from.

📎 Additional Context

  • Affected Files: Primarily storage/*.rs (and any other modules assuming Linux paths).
  • Recommended Crate: directories v5.0+
  • Future Scope: While this issue focuses on Windows, using ProjectDirs will automatically lay the groundwork for proper macOS support in the future.

✅ Acceptance Criteria

  • directories (or dirs) crate is added to Cargo.toml.
  • All hardcoded Linux paths in storage/ are replaced with OS-agnostic resolution.
  • The project successfully compiles for Windows (cargo check --target x86_64-pc-windows-msvc).
  • Manual testing confirms config files are saved to %APPDATA% (or equivalent) on Windows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or requestgood first issueGood for newcomershelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions