Skip to content

Replace string-typed file paths with PathBuf / impl AsRef<Path> #283

@emlautarom1

Description

@emlautarom1

Description

Several public and internal APIs represent filesystem paths as String / &str / impl AsRef<str> instead of the idiomatic std::path::PathBuf or impl AsRef<Path>. This leads to:

  • Lossy conversions (.to_string_lossy()) when the two representations must be bridged.
  • String concatenation used to build paths (format!("{dir}/{prefix}.json")) instead of Path::join, which is not cross-platform and bypasses the type system.
  • Error messages that store paths as String, losing structural information.

All occurrences should be migrated to PathBuf (owned) or impl AsRef<Path> (borrowed generic), consistent with the Rust standard library conventions.

Affected locations

crates/dkg/src/disk.rs

Location Issue
Struct field Config::def_file: String Should be PathBuf
Struct field Config::data_dir: String Should be PathBuf
write_lock(data_dir: impl AsRef<str>, …) (≈ line 207) Parameter should be impl AsRef<Path>
check_writes(data_dir: impl AsRef<str>) (≈ line 285) Parameter should be impl AsRef<Path>
keys_dir.to_string_lossy().to_owned() (≈ line 190) Lossy PathBuf → String conversion; downstream API is the root cause

crates/dkg/src/dkg.rs

Location Issue
Struct field Config::def_file: String Should be PathBuf
Struct field Config::data_dir: String Should be PathBuf

crates/eth2util/src/keystore/store.rs

Location Issue
store_keys(…, dir: impl AsRef<str>) (≈ line 60) Should be impl AsRef<Path>
store_keys_insecure(…, dir: impl AsRef<str>, …) (≈ line 42) Should be impl AsRef<Path>
store_keys_internal(…, dir: impl AsRef<str>, …) (≈ line 65) Should be impl AsRef<Path>
load_password(key_file: impl AsRef<str>) (≈ line 158) Should be impl AsRef<Path>
store_password(key_file: impl AsRef<str>, …) (≈ line 175) Should be impl AsRef<Path>
check_dir(dir: impl AsRef<str>) (≈ line 189) Should be impl AsRef<Path>
write_file(path: impl AsRef<str>, …) (≈ line 220) Should be impl AsRef<Path>
format!("{dir}/{prefix}{i}.json") (≈ line 78) Use Path::join instead

crates/eth2util/src/keystore/load.rs

Location Issue
load_files_unordered(dir: impl AsRef<str>) (≈ line 81) Should be impl AsRef<Path>
load_files_recursively(dir: impl AsRef<str>) (≈ line 130) Should be impl AsRef<Path>
extract_file_index(filename: impl AsRef<str>) (≈ line 257) Should be impl AsRef<Path>

crates/eth2util/src/keystore/error.rs

Location Issue
DirNotExist { path: String } (≈ line 10) Should be PathBuf
NotADirectory { path: String } (≈ line 17) Should be PathBuf
PasswordNotFound { path: String } (≈ line 28) Should be PathBuf
KeystoreNotFound { path: String } (≈ line 123) Should be PathBuf

crates/cli/src/commands/relay.rs

Location Issue
RelayLogFlags::log_output_path: String (≈ line 272) Should be PathBuf

Acceptance criteria

  • All struct fields that represent filesystem paths use PathBuf.
  • All function/method parameters that receive filesystem paths accept impl AsRef<Path>.
  • No .to_string_lossy() calls on paths that are immediately passed into another API.
  • Path construction uses Path::join / PathBuf::push instead of format! string concatenation.
  • Existing tests continue to pass (cargo test --workspace --all-features).
  • No new clippy warnings (cargo clippy --workspace --all-targets --all-features -- -D warnings).

Metadata

Metadata

Assignees

No one assigned

    Labels

    rustPull requests that update rust code

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions