From 43e1a12b5bce11b4a28a53acca243e35c2be6d3e Mon Sep 17 00:00:00 2001 From: evuez Date: Wed, 3 Apr 2024 22:43:16 +0200 Subject: Initial commit --- src/main.rs | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/main.rs (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..3d0eee5 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,65 @@ +#![deny(clippy::all)] +#![warn(clippy::pedantic)] +#![allow(clippy::module_name_repetitions)] +#![feature(file_create_new)] +#![feature(map_try_insert)] +#![feature(result_option_inspect)] + +mod client; +mod common; +mod index; +mod server; + +// use fs::FileSystem; +// use index::Index; +use client::fs::FileSystem; +use serde::{Deserialize, Serialize}; +use server::Server; +use std::env; + +const CONFIG: &str = "carton.toml"; + +#[derive(Serialize, Deserialize)] +struct Config { + server: server::Config, + client: client::Config, +} + +fn main() { + let mut logger = env_logger::Builder::from_default_env(); + logger.filter(None, log::LevelFilter::Debug).init(); + + // Config + let config: Config = toml::from_str( + &std::fs::read_to_string(CONFIG).expect("Missing config file at {CONFIG:?}"), + ) + .expect("Invalid config file at {CONFIG:?}"); + + // Args + let args: Vec = env::args().collect(); + + if args.len() < 2 { + println!("Missing command for carton."); + return; + } + + match args[1].as_str() { + // "index-scan" => cmd_index_scan(&args[2..]), + // "reindex" => cmd_index_scan(&args[2..]), + "fs-mount" => cmd_fs_mount(config, &args[2..]), + _ => todo!(), + } +} + +// fn cmd_index_scan(args: &[String]) { +// index::spawn_scan(Path::new(ROOT)); +// } + +fn cmd_fs_mount(config: Config, _args: &[String]) { + let server = Server::new(&config.server).expect("Couldn't initialize server."); + + // let index = Index::new(Path::new(ROOT)).unwrap(); + + let fs = FileSystem::new(server); + fs.mount(&config.client.fs.mountpoint).unwrap(); +} -- cgit v1.2.3