Browse Source

Change PathBuf to Path where it is possible

pull/53/head
Rodolphe Bréard 3 years ago
parent
commit
6ef9b14a54
  1. 8
      acmed/src/config.rs
  2. 6
      acmed/src/storage.rs

8
acmed/src/config.rs

@ -662,8 +662,8 @@ fn init_directories(config: &Config) -> Result<(), Error> {
Ok(())
}
fn get_cnf_path(from: &PathBuf, file: &str) -> Result<Vec<PathBuf>, Error> {
let mut path = from.clone().canonicalize()?;
fn get_cnf_path(from: &Path, file: &str) -> Result<Vec<PathBuf>, Error> {
let mut path = from.to_path_buf().canonicalize()?;
path.pop();
path.push(file);
let err = format!("{:?}: invalid UTF-8 path", path);
@ -681,14 +681,14 @@ fn get_cnf_path(from: &PathBuf, file: &str) -> Result<Vec<PathBuf>, Error> {
Ok(g)
}
fn read_cnf(path: &PathBuf, loaded_files: &mut BTreeSet<PathBuf>) -> Result<Config, Error> {
fn read_cnf(path: &Path, loaded_files: &mut BTreeSet<PathBuf>) -> Result<Config, Error> {
let path = path.canonicalize()?;
if loaded_files.contains(&path) {
info!("{}: configuration file already loaded", path.display());
return Ok(Config::default());
}
loaded_files.insert(path.clone());
info!("{}: loading configuration file", path.display());
info!("{}: loading configuration file", &path.display());
let mut file =
File::open(&path).map_err(|e| Error::from(e).prefix(&path.display().to_string()))?;
let mut contents = String::new();

6
acmed/src/storage.rs

@ -9,7 +9,7 @@ use std::collections::HashMap;
use std::fmt;
use std::fs::{File, OpenOptions};
use std::io::{Read, Write};
use std::path::PathBuf;
use std::path::{Path, PathBuf};
#[cfg(target_family = "unix")]
use std::os::unix::fs::OpenOptionsExt;
@ -123,7 +123,7 @@ fn get_file_path(fm: &FileManager, file_type: FileType) -> Result<PathBuf, Error
Ok(path)
}
fn read_file(fm: &FileManager, path: &PathBuf) -> Result<Vec<u8>, 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 contents = vec![];
@ -132,7 +132,7 @@ fn read_file(fm: &FileManager, path: &PathBuf) -> Result<Vec<u8>, Error> {
}
#[cfg(unix)]
fn set_owner(fm: &FileManager, path: &PathBuf, file_type: FileType) -> Result<(), Error> {
fn set_owner(fm: &FileManager, path: &Path, file_type: FileType) -> Result<(), Error> {
let (uid, gid) = match file_type {
FileType::Certificate => (fm.cert_file_owner.to_owned(), fm.cert_file_group.to_owned()),
FileType::PrivateKey => (fm.pk_file_owner.to_owned(), fm.pk_file_group.to_owned()),

Loading…
Cancel
Save