[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:
- Add Dependency: Add the
directories (or dirs) crate to Cargo.toml.
- 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();
- 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
[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
undertow-protocol.⚙️ 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:
directories(ordirs) crate toCargo.toml.storage/*.rs: Replace hardcoded Linux paths with OS-aware path resolution.Example:
cargo check --target x86_64-pc-windows-msvc).🔄 Alternatives Considered
#[cfg(target_os = "...")]macros: Writing customif/elseblocks for every OS. Rejected: Reinvents the wheel, prone to edge-case bugs, and harder to maintain if we add macOS support later../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
storage/*.rs(and any other modules assuming Linux paths).directoriesv5.0+ProjectDirswill automatically lay the groundwork for proper macOS support in the future.✅ Acceptance Criteria
directories(ordirs) crate is added toCargo.toml.storage/are replaced with OS-agnostic resolution.cargo check --target x86_64-pc-windows-msvc).%APPDATA%(or equivalent) on Windows.