Skip to content

Commit 372043a

Browse files
committed
refactor: return anyhow::Result from write_private_file_atomic
New code under src/ uses anyhow::Result and ?-based propagation; convert the atomic write helper's error type to match. Callers already add their own context or propagate through anyhow, so this only drops the io::Result outlier.
1 parent 0016e5d commit 372043a

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/core/auth.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,16 @@ pub(crate) fn write_private_file(path: &Path, contents: &[u8]) -> std::io::Resul
113113
/// The bytes go to a process-unique temporary sibling first, then a rename swaps
114114
/// it over `path`. The unique suffix (pid plus a per-process counter) keeps two
115115
/// concurrent writers from sharing one temp file and renaming each other's
116-
/// half-written bytes into place. On a failed rename the temp file is removed
117-
/// best-effort so aborted writes do not accumulate.
118-
pub(crate) fn write_private_file_atomic(path: &Path, contents: &[u8]) -> std::io::Result<()> {
116+
/// half-written bytes into place. On a failed write or rename the temp file is
117+
/// removed best-effort so aborted writes do not accumulate.
118+
pub(crate) fn write_private_file_atomic(path: &Path, contents: &[u8]) -> Result<()> {
119119
let tmp = unique_temp_path(path);
120120
// Clean up on either failure (write or rename). Each attempt uses a fresh
121121
// unique name, so a leaked temp from a partial write would otherwise persist.
122122
if let Err(error) = write_private_file(&tmp, contents).and_then(|()| std::fs::rename(&tmp, path))
123123
{
124124
let _ = std::fs::remove_file(&tmp);
125-
return Err(error);
125+
return Err(error.into());
126126
}
127127
Ok(())
128128
}

0 commit comments

Comments
 (0)