diff --git a/src/config_structure.rs b/src/config_structure.rs new file mode 100644 index 0000000000000000000000000000000000000000..7cca20edcbc9144cff416fe852fedbc682e30b94 --- /dev/null +++ b/src/config_structure.rs @@ -0,0 +1,78 @@ +/// This module contains the structure of the gblk config file +use serde_derive::{Deserialize, Serialize}; +use toml::{self, Value}; + +/// /// Structure containing the global definition of the borg config file +#[derive(Debug, Deserialize, Serialize, Clone)] +pub struct Config { + pub repository: Option<Repository>, + pub gblk_prune: Option<GblkConfig>, +} + +/// Structure that store the current borg configuration for the project +#[derive(Debug, Deserialize, Serialize, Clone)] +pub struct Repository { + pub version: Value, + pub segments_per_dir: usize, + pub max_segment_size: usize, + pub append_only: usize, + pub storage_quota: usize, + pub additional_free_space: usize, + pub id: String, +} + +/// Structure corresponding to the gblk prune config to automatically use +/// inside a project +#[derive(Debug, Deserialize, Serialize, Clone)] +pub struct GblkConfig { + pub save_space: Option<bool>, + pub keep_within: Option<String>, + pub keep_last: Option<usize>, + pub keep_minutely: Option<usize>, + pub keep_hourly: Option<usize>, + pub keep_daily: Option<usize>, + pub keep_weekly: Option<usize>, + pub keep_monthly: Option<usize>, + pub keep_yearly: Option<usize>, + pub prefix: Option<String>, + pub glob_archives: Option<String>, +} + +impl GblkConfig { + pub fn empty(&self) -> bool { + if self.save_space != None { + return false; + }; + if self.keep_within != None { + return false; + }; + if self.keep_last != None { + return false; + }; + if self.keep_minutely != None { + return false; + }; + if self.keep_hourly != None { + return false; + }; + if self.keep_daily != None { + return false; + }; + if self.keep_weekly != None { + return false; + }; + if self.keep_monthly != None { + return false; + }; + if self.keep_yearly != None { + return false; + }; + if self.prefix != None { + return false; + }; + if self.glob_archives != None { + return false; + }; + true + } +} diff --git a/src/configt.rs b/src/configt.rs index 5d9d75a6af9186bb8302d506bfdd0a7bc90f03bb..2420c60b1e40c58d0cc0fb4a5b1e917f8a582abb 100644 --- a/src/configt.rs +++ b/src/configt.rs @@ -1,12 +1,12 @@ use crate::commit; +use crate::config_structure::{Config, GblkConfig}; use crate::prune::{new_prune, prune_launcher}; use clap::Args; use colored::Colorize; use home; use regex::Regex; -use serde_derive::{Deserialize, Serialize}; use std::{path::PathBuf, process::exit}; -use toml::{self, Value}; +use toml; #[derive(Debug, Args)] pub(crate) struct PartialPrune { @@ -47,85 +47,6 @@ pub(crate) struct PartialPrune { pub(crate) force: usize, } -// ================================ toml structure of borg config - -/// Structure containing the global definition of the borg config file -#[derive(Debug, Deserialize, Serialize, Clone)] -pub struct Config { - repository: Option<Repository>, - gblk_prune: Option<GblkConfig>, -} - -/// Structure that store the current borg configuration for the project -#[derive(Debug, Deserialize, Serialize, Clone)] -struct Repository { - version: Value, - segments_per_dir: usize, - max_segment_size: usize, - append_only: usize, - storage_quota: usize, - additional_free_space: usize, - id: String, -} - -/// Structure corresponding to the gblk prune config to automatically use -/// inside a project -#[derive(Debug, Deserialize, Serialize, Clone)] -pub struct GblkConfig { - pub save_space: Option<bool>, - pub keep_within: Option<String>, - pub keep_last: Option<usize>, - pub keep_minutely: Option<usize>, - pub keep_hourly: Option<usize>, - pub keep_daily: Option<usize>, - pub keep_weekly: Option<usize>, - pub keep_monthly: Option<usize>, - pub keep_yearly: Option<usize>, - pub prefix: Option<String>, - pub glob_archives: Option<String>, -} - -impl GblkConfig { - fn empty(&self) -> bool { - if self.save_space != None { - return false; - }; - if self.keep_within != None { - return false; - }; - if self.keep_last != None { - return false; - }; - if self.keep_minutely != None { - return false; - }; - if self.keep_hourly != None { - return false; - }; - if self.keep_daily != None { - return false; - }; - if self.keep_weekly != None { - return false; - }; - if self.keep_monthly != None { - return false; - }; - if self.keep_yearly != None { - return false; - }; - if self.prefix != None { - return false; - }; - if self.glob_archives != None { - return false; - }; - true - } -} - -// =================== Functions - /// Get the config file inside borg folder /// # Return /// A pathbuf variable containing the location of borg config file for the diff --git a/src/main.rs b/src/main.rs index 936a4e4bf06a079d6bd50f63b26bd6eaea932490..72b32b46ca046dfeab8de00ff642a44183d57ade 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,7 @@ mod init; mod list; mod mount; mod prune; +mod config_structure; #[derive(Debug, Parser)] #[clap(name = "gblk")] diff --git a/src/prune.rs b/src/prune.rs index e3dc37e2d55595dd4440398edc6a84057bdf156d..1e01c2e118923b9c9d727cc5fb1683d85e745c7a 100644 --- a/src/prune.rs +++ b/src/prune.rs @@ -1,5 +1,6 @@ use crate::commit; -use crate::configt::{GblkConfig, PartialPrune}; +use crate::config_structure::GblkConfig; +use crate::configt::PartialPrune; use clap::Args; use std::{ collections::HashMap as HM,