Skip to content
Snippets Groups Projects
Verified Commit f4b44008 authored by nfontrod's avatar nfontrod
Browse files

src/main.rs src/prune.rs src/config_structure.rs src/configt.rs: move the...

src/main.rs src/prune.rs src/config_structure.rs src/configt.rs: move the configuration file structure in its own file config_structure.rs
parent 77e2d9cc
Branches
No related tags found
No related merge requests found
/// 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
}
}
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
......
......@@ -15,6 +15,7 @@ mod init;
mod list;
mod mount;
mod prune;
mod config_structure;
#[derive(Debug, Parser)]
#[clap(name = "gblk")]
......
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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment