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).
Description
Several public and internal APIs represent filesystem paths as
String/&str/impl AsRef<str>instead of the idiomaticstd::path::PathBuforimpl AsRef<Path>. This leads to:.to_string_lossy()) when the two representations must be bridged.format!("{dir}/{prefix}.json")) instead ofPath::join, which is not cross-platform and bypasses the type system.String, losing structural information.All occurrences should be migrated to
PathBuf(owned) orimpl AsRef<Path>(borrowed generic), consistent with the Rust standard library conventions.Affected locations
crates/dkg/src/disk.rsConfig::def_file: StringPathBufConfig::data_dir: StringPathBufwrite_lock(data_dir: impl AsRef<str>, …)(≈ line 207)impl AsRef<Path>check_writes(data_dir: impl AsRef<str>)(≈ line 285)impl AsRef<Path>keys_dir.to_string_lossy().to_owned()(≈ line 190)PathBuf → Stringconversion; downstream API is the root causecrates/dkg/src/dkg.rsConfig::def_file: StringPathBufConfig::data_dir: StringPathBufcrates/eth2util/src/keystore/store.rsstore_keys(…, dir: impl AsRef<str>)(≈ line 60)impl AsRef<Path>store_keys_insecure(…, dir: impl AsRef<str>, …)(≈ line 42)impl AsRef<Path>store_keys_internal(…, dir: impl AsRef<str>, …)(≈ line 65)impl AsRef<Path>load_password(key_file: impl AsRef<str>)(≈ line 158)impl AsRef<Path>store_password(key_file: impl AsRef<str>, …)(≈ line 175)impl AsRef<Path>check_dir(dir: impl AsRef<str>)(≈ line 189)impl AsRef<Path>write_file(path: impl AsRef<str>, …)(≈ line 220)impl AsRef<Path>format!("{dir}/{prefix}{i}.json")(≈ line 78)Path::joininsteadcrates/eth2util/src/keystore/load.rsload_files_unordered(dir: impl AsRef<str>)(≈ line 81)impl AsRef<Path>load_files_recursively(dir: impl AsRef<str>)(≈ line 130)impl AsRef<Path>extract_file_index(filename: impl AsRef<str>)(≈ line 257)impl AsRef<Path>crates/eth2util/src/keystore/error.rsDirNotExist { path: String }(≈ line 10)PathBufNotADirectory { path: String }(≈ line 17)PathBufPasswordNotFound { path: String }(≈ line 28)PathBufKeystoreNotFound { path: String }(≈ line 123)PathBufcrates/cli/src/commands/relay.rsRelayLogFlags::log_output_path: String(≈ line 272)PathBufAcceptance criteria
PathBuf.impl AsRef<Path>..to_string_lossy()calls on paths that are immediately passed into another API.Path::join/PathBuf::pushinstead offormat!string concatenation.cargo test --workspace --all-features).clippywarnings (cargo clippy --workspace --all-targets --all-features -- -D warnings).