Skip to content

Commit 79266e9

Browse files
committed
fix(auth): address Gemini review comments - OnceLock expect + permission warnings
- Replace unwrap_or(candidate) with expect() in cache_key closure for clearer OnceLock race invariant: if set() fails, get() is guaranteed to return Some - Emit eprintln! warnings (rather than silently ignoring) when set_permissions fails on the encryption key directory, matching the warning pattern used throughout the codebase (src/auth_commands.rs, helpers/workflows.rs, etc.)
1 parent c820b43 commit 79266e9

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

src/credential_store.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ fn get_or_create_key() -> anyhow::Result<[u8; 32]> {
3434
if KEY.set(candidate).is_ok() {
3535
candidate
3636
} else {
37-
KEY.get().copied().unwrap_or(candidate)
37+
// If set() fails, another thread already initialized the key. .get() is
38+
// guaranteed to return Some at this point.
39+
*KEY.get()
40+
.expect("key must be initialized if OnceLock::set() failed")
3841
}
3942
};
4043

@@ -86,10 +89,13 @@ fn get_or_create_key() -> anyhow::Result<[u8; 32]> {
8689
#[cfg(unix)]
8790
{
8891
use std::os::unix::fs::PermissionsExt;
89-
let _ = std::fs::set_permissions(
90-
parent,
91-
std::fs::Permissions::from_mode(0o700),
92-
);
92+
if let Err(e) =
93+
std::fs::set_permissions(parent, std::fs::Permissions::from_mode(0o700))
94+
{
95+
eprintln!(
96+
"Warning: failed to set secure permissions on key directory: {e}"
97+
);
98+
}
9399
}
94100
}
95101

@@ -144,7 +150,10 @@ fn get_or_create_key() -> anyhow::Result<[u8; 32]> {
144150
#[cfg(unix)]
145151
{
146152
use std::os::unix::fs::PermissionsExt;
147-
let _ = std::fs::set_permissions(parent, std::fs::Permissions::from_mode(0o700));
153+
if let Err(e) = std::fs::set_permissions(parent, std::fs::Permissions::from_mode(0o700))
154+
{
155+
eprintln!("Warning: failed to set secure permissions on key directory: {e}");
156+
}
148157
}
149158
}
150159

0 commit comments

Comments
 (0)