summaryrefslogtreecommitdiff
path: root/src/bin/obnam-server.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-03-03 08:57:25 +0000
committerLars Wirzenius <liw@liw.fi>2021-03-03 08:57:25 +0000
commite80d78e7f0812ef5eb4cc2b4e93e1c241e0f4541 (patch)
tree513ec0f11cc219d6b8274cc1c20b84e62783d065 /src/bin/obnam-server.rs
parentcb68600fef426841147e322f49b2568ebaf8a8dc (diff)
parent8f3b51d85eb3f192b23357b94a23f06ba2a7fff6 (diff)
downloadobnam2-e80d78e7f0812ef5eb4cc2b4e93e1c241e0f4541.tar.gz
Merge branch 'config' into 'main'
Configuration file handling improvements Closes #74 See merge request larswirzenius/obnam!107
Diffstat (limited to 'src/bin/obnam-server.rs')
-rw-r--r--src/bin/obnam-server.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/bin/obnam-server.rs b/src/bin/obnam-server.rs
index d4513fa..ddbfce3 100644
--- a/src/bin/obnam-server.rs
+++ b/src/bin/obnam-server.rs
@@ -1,15 +1,16 @@
+use anyhow::Context;
use bytes::Bytes;
use log::{debug, error, info};
use obnam::chunk::DataChunk;
use obnam::chunkid::ChunkId;
use obnam::chunkmeta::ChunkMeta;
use obnam::indexedstore::IndexedStore;
-use obnam::server::{Config, ConfigError};
+use obnam::server::{ServerConfig, ServerConfigError};
use serde::Serialize;
use std::collections::HashMap;
use std::default::Default;
use std::net::{SocketAddr, ToSocketAddrs};
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
use std::sync::Arc;
use structopt::StructOpt;
use tokio::sync::Mutex;
@@ -28,13 +29,13 @@ async fn main() -> anyhow::Result<()> {
pretty_env_logger::init();
let opt = Opt::from_args();
- let config = Config::read_config(&opt.config).unwrap();
+ let config = load_config(&opt.config)?;
let addresses: Vec<SocketAddr> = config.address.to_socket_addrs()?.collect();
if addresses.is_empty() {
error!("specified address is empty set: {:?}", addresses);
eprintln!("ERROR: server address is empty: {:?}", addresses);
- return Err(ConfigError::BadServerAddress.into());
+ return Err(ServerConfigError::BadServerAddress.into());
}
let store = IndexedStore::new(&config.chunks)?;
@@ -83,6 +84,16 @@ async fn main() -> anyhow::Result<()> {
Ok(())
}
+fn load_config(filename: &Path) -> Result<ServerConfig, anyhow::Error> {
+ let config = ServerConfig::read_config(&filename).with_context(|| {
+ format!(
+ "Couldn't read default configuration file {}",
+ filename.display()
+ )
+ })?;
+ Ok(config)
+}
+
pub async fn create_chunk(
store: Arc<Mutex<IndexedStore>>,
meta: String,