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
|
@ -25,6 +25,7 @@ xmpp = "0.5"
|
|||
hmac = "0.12"
|
||||
sha2 = "0.10"
|
||||
hex = "0.4"
|
||||
camino = { version = "1.1", features = ["serde"] }
|
||||
|
||||
[patch.crates-io]
|
||||
forgejo-hooks = { path = "forgejo-hooks" }
|
||||
|
|
|
@ -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)
|
||||
path.canonicalize_utf8()?
|
||||
} else {
|
||||
path.to_path_buf()
|
||||
}
|
||||
} 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")
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -28,9 +28,9 @@ use crate::error::Error;
|
|||
use crate::hook::Hook;
|
||||
use crate::web::hooks;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use camino::Utf8PathBuf;
|
||||
use clap::{command, value_parser, Arg};
|
||||
use hyper::{server::conn::http1, service::service_fn};
|
||||
use hyper_util::rt::tokio::{TokioIo, TokioTimer};
|
||||
|
@ -46,11 +46,11 @@ async fn main() -> Result<!, Error> {
|
|||
.short('c')
|
||||
.long("config")
|
||||
.required(false)
|
||||
.value_parser(value_parser!(PathBuf)),
|
||||
.value_parser(value_parser!(Utf8PathBuf)),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let config = Config::from_arg(matches.get_one::<PathBuf>("config"))?;
|
||||
let config = Config::from_arg(matches.get_one::<Utf8PathBuf>("config"))?;
|
||||
|
||||
let (value_tx, mut value_rx) = mpsc::unbounded_channel::<Hook>();
|
||||
|
||||
|
|
Loading…
Reference in a new issue