Use Utf8PathBuf
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
ad3bcc88de
commit
66e4131bd3
3 changed files with 11 additions and 14 deletions
|
|
@ -15,8 +15,8 @@
|
|||
|
||||
use std::io::{Error as IoError, ErrorKind as IoErrorKind};
|
||||
use std::net::{IpAddr, Ipv6Addr, SocketAddr};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use camino::{Utf8Path, Utf8PathBuf};
|
||||
use jid::BareJid;
|
||||
use log::debug;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -57,7 +57,7 @@ impl Config {
|
|||
SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), 3000)
|
||||
}
|
||||
|
||||
pub fn from_file(file: PathBuf) -> Result<Config, Error> {
|
||||
pub fn from_file(file: Utf8PathBuf) -> Result<Config, Error> {
|
||||
if file.try_exists().is_err() {
|
||||
let err = IoError::new(IoErrorKind::NotFound, format!("{:?} not found", file));
|
||||
return Err(Error::Io(err));
|
||||
|
|
@ -68,20 +68,16 @@ impl Config {
|
|||
Ok(toml::from_str(&buf)?)
|
||||
}
|
||||
|
||||
pub fn from_arg(file: Option<&PathBuf>) -> Result<Config, Error> {
|
||||
pub fn from_arg(file: Option<&Utf8PathBuf>) -> Result<Config, Error> {
|
||||
let path = if let Some(path) = file {
|
||||
// Provided by --config flag
|
||||
if !path.starts_with("/") {
|
||||
std::env::current_dir()?.join(path)
|
||||
} else {
|
||||
path.to_path_buf()
|
||||
}
|
||||
path.canonicalize_utf8()?
|
||||
} else {
|
||||
let confdir: PathBuf = match std::env::var("XDG_CONFIG_HOME") {
|
||||
Ok(ref dir) => Path::new(dir).to_path_buf(),
|
||||
let confdir: Utf8PathBuf = match std::env::var("XDG_CONFIG_HOME") {
|
||||
Ok(ref dir) => Utf8Path::new(dir).to_path_buf(),
|
||||
Err(_) => {
|
||||
let home = std::env::var("HOME")?;
|
||||
Path::new(home.as_str()).join(".config")
|
||||
Utf8Path::new(home.as_str()).join(".config")
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue