Skip to content

Commit

Permalink
Add some missing file path in log messages
Browse files Browse the repository at this point in the history
Rel #24
  • Loading branch information
breard-r committed May 7, 2022
1 parent 7325bac commit 01894bc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- An invalid reference in the command line arguments has been fixed.
- Some missing file path in log messages has been added.


## [0.19.0] - 2022-04-17
Expand Down
4 changes: 3 additions & 1 deletion acmed/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,9 @@ fn get_cnf_path(from: &Path, file: &str) -> Result<Vec<PathBuf>, Error> {
}

fn read_cnf(path: &Path, loaded_files: &mut BTreeSet<PathBuf>) -> Result<Config, Error> {
let path = path.canonicalize()?;
let path = path
.canonicalize()
.map_err(|e| Error::from(e).prefix(&path.display().to_string()))?;
if loaded_files.contains(&path) {
info!("{}: configuration file already loaded", path.display());
return Ok(Config::default());
Expand Down
2 changes: 1 addition & 1 deletion acmed/src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ where
hook.name, &file_name
));
let stdin = cmd.stdin.as_mut().ok_or("stdin not found")?;
let file = File::open(&file_name)?;
let file = File::open(&file_name).map_err(|e| Error::from(e).prefix(&file_name))?;
let buf_reader = BufReader::new(file);
for line in buf_reader.lines() {
let line = format!("{}\n", line?);
Expand Down
4 changes: 3 additions & 1 deletion acmed/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ fn get_session(root_certs: &[String]) -> Result<Session, Error> {
#[cfg(feature = "crypto_openssl")]
{
let mut buff = Vec::new();
File::open(crt_file)?.read_to_end(&mut buff)?;
File::open(crt_file)
.map_err(|e| Error::from(e).prefix(crt_file))?
.read_to_end(&mut buff)?;
let crt = X509Certificate::from_pem_native(&buff)?;
session.add_root_certificate(crt);
}
Expand Down
16 changes: 11 additions & 5 deletions acmed/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ fn get_file_path(fm: &FileManager, file_type: FileType) -> Result<PathBuf, Error

fn read_file(fm: &FileManager, path: &Path) -> Result<Vec<u8>, Error> {
fm.trace(&format!("reading file {:?}", path));
let mut file = File::open(path)?;
let mut file =
File::open(path).map_err(|e| Error::from(e).prefix(&path.display().to_string()))?;
let mut contents = vec![];
file.read_to_end(&mut contents)?;
Ok(contents)
Expand Down Expand Up @@ -210,13 +211,18 @@ fn write_file(fm: &FileManager, file_type: FileType, data: &[u8]) -> Result<(),
FileType::PrivateKey => fm.pk_file_mode,
FileType::Account => crate::DEFAULT_ACCOUNT_FILE_MODE,
});
options.write(true).create(true).open(&path)?
options
.write(true)
.create(true)
.open(&path)
.map_err(|e| Error::from(e).prefix(&path.display().to_string()))?
} else {
File::create(&path)?
File::create(&path).map_err(|e| Error::from(e).prefix(&path.display().to_string()))?
};
file.write_all(data)?;
file.write_all(data)
.map_err(|e| Error::from(e).prefix(&path.display().to_string()))?;
if cfg!(unix) {
set_owner(fm, &path, file_type)?;
set_owner(fm, &path, file_type).map_err(|e| e.prefix(&path.display().to_string()))?;
}

if is_new {
Expand Down

0 comments on commit 01894bc

Please sign in to comment.