Add API for propagating cursor locations #61
1 changed files with 13 additions and 11 deletions
Always write config
commit
1475a549d4
|
|
@ -2,7 +2,7 @@ use std::path::Path;
|
||||||
|
|
||||||
use anyhow::{Context as _, Result};
|
use anyhow::{Context as _, Result};
|
||||||
use database_config::DatabaseConfig;
|
use database_config::DatabaseConfig;
|
||||||
use log::{info, warn};
|
use log::info;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use server_config::ServerConfig;
|
use server_config::ServerConfig;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|
@ -24,22 +24,24 @@ pub struct Config {
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub async fn read_or_create(path: &Path) -> Result<Self> {
|
pub async fn read_or_create(path: &Path) -> Result<Self> {
|
||||||
if path.exists() {
|
let config = if path.exists() {
|
||||||
info!(
|
info!(
|
||||||
"Loading configuration from '{}'",
|
"Loading configuration from '{}'",
|
||||||
path.canonicalize().unwrap().display()
|
path.canonicalize().unwrap().display()
|
||||||
);
|
);
|
||||||
Self::load_from_file(path).await
|
Self::load_from_file(path).await?
|
||||||
} else {
|
} else {
|
||||||
let config = Self::default();
|
Self::default()
|
||||||
|
};
|
||||||
|
|
||||||
config.write(path).await?;
|
config.write(path).await?;
|
||||||
warn!(
|
info!(
|
||||||
"Configuration file not found, wrote default configuration to '{}'",
|
"Updated configuration at '{}'",
|
||||||
path.canonicalize().unwrap().display()
|
path.canonicalize().unwrap().display()
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn load_from_file(path: &Path) -> Result<Self> {
|
pub async fn load_from_file(path: &Path) -> Result<Self> {
|
||||||
let contents = fs::read_to_string(path).await.with_context(|| {
|
let contents = fs::read_to_string(path).await.with_context(|| {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue