From 8ba536bc4dfac1b3551c1dd923237add4ba51226 Mon Sep 17 00:00:00 2001 From: axtlos <3alouchi2006@gmail.com> Date: Wed, 1 Sep 2021 21:43:09 +0200 Subject: [PATCH] added hard-coded fallback config instead the config is for some reason is empty, also changed config space in /etc/ame.toml --- config.toml => ame.toml | 0 src/main.rs | 26 ++++++++++++++++++++++---- src/mods/config.rs | 26 ++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 8 deletions(-) rename config.toml => ame.toml (100%) diff --git a/config.toml b/ame.toml similarity index 100% rename from config.toml rename to ame.toml diff --git a/src/main.rs b/src/main.rs index 23c3ad3..e9dd986 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ mod mods; use toml; use serde; use mods::{clearcache::clearcache, clone::clone, help::help, install::install, search::{a_search, r_search}, uninstall::uninstall, upgrade::upgrade, flatpak::flatpak, snap::snap, config::printconfig}; -use std::{fs::File, io::prelude::*, env, process::exit, process::Command}; +use std::{fs, fs::File, io::prelude::*, env, process::exit, process::Command}; #[derive(serde::Deserialize)] struct General { @@ -32,11 +32,29 @@ struct AUR { fn main() { let args: Vec = env::args().collect(); - let mut file = File::open(format!("{}/.config/ame/config.toml", std::env::var("HOME").unwrap())).expect("Unable to open the Config file"); + let mut confile = File::open("/etc/ame.toml").expect("Unable to open the Config file, did you delete ame.toml from /etc/??"); let mut config = String::new(); - file.read_to_string(&mut config).expect("Unable to read the Config file"); - let configfile: General = toml::from_str(&config).unwrap(); + let conftostring = fs::read_to_string("/etc/ame.toml").expect("unable to open config file!"); + let configfile: General = toml::from_str(r#" + cache = "/home/user/.cache/ame" + [backends] + pacman = true + flatpak = true + snap = false + aur = true + + [pacman] + noconfirm = false + + [aur] + clone_path = "/home/user/.cache/ame" + "#).unwrap(); + if conftostring != "" { + confile.read_to_string(&mut config).expect("Unable to read the Config file"); + let configfile: General = toml::from_str(&config).unwrap(); + } + if args.len() <= 1 { help(); exit(1); diff --git a/src/mods/config.rs b/src/mods/config.rs index 31855ef..75465ab 100644 --- a/src/mods/config.rs +++ b/src/mods/config.rs @@ -1,6 +1,6 @@ use toml; use serde; -use std::{fs::File, io::prelude::*, env}; +use std::{fs, fs::File, io::prelude::*, env}; #[derive(serde::Deserialize)] @@ -33,10 +33,28 @@ struct AUR { pub fn printconfig() { let args: Vec = env::args().collect(); - let mut file = File::open(format!("{}/.config/ame/config.toml", std::env::var("HOME").unwrap())).expect("Unable to open the Config file"); + let mut confile = File::open("/etc/ame.toml").expect("Unable to open the Config file, did you delete ame.toml from /etc/??"); let mut config = String::new(); - file.read_to_string(&mut config).expect("Unable to read the Config file"); - let configfile: General = toml::from_str(&config).unwrap(); + let conftostring = fs::read_to_string("/etc/ame.toml").expect("unable to open config file!"); + let configfile: General = toml::from_str(r#" + cache = "/home/user/.cache/ame" + + [backends] + pacman = true + flatpak = true + snap = false + aur = true + + [pacman] + noconfirm = false + + [aur] + clone_path = "/home/user/.cache/ame" + "#).unwrap(); + if conftostring != "" { + confile.read_to_string(&mut config).expect("Unable to read the Config file"); + let configfile: General = toml::from_str(&config).unwrap(); + } println!("\ General: Cache directory: {}