use std::{
fs,
io::{self},
path::Path,
};
pub fn try_read<P: AsRef<Path>>(path: P) -> ArtifactoryAuthResult<Option<Vec<u8>>> {
let path = path.as_ref();
match fs::read(&path).map(Some) {
Ok(contents) => Ok(contents),
Err(err) => {
if err.kind() == io::ErrorKind::NotFound {
Ok(None)
} else {
Err(ArtifactoryAuthError::read_error(err, path))
}
}
}
}
#[cfg(test)]
pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> ArtifactoryAuthResult<()> {
let path = path.as_ref();
fs::write(path, contents).map_err(|source| ArtifactoryAuthError::write_error(source, path))
}
use crate::error::{ArtifactoryAuthError, ArtifactoryAuthResult};