Additional tweaks

This commit is contained in:
Beefki 2017-10-25 20:23:30 -05:00
parent 1ff420fb49
commit fc0f7a2fff
2 changed files with 11 additions and 14 deletions

View File

@ -26,8 +26,8 @@ fn main() {
ruxconf.push(".config/rux/rux.conf"); ruxconf.push(".config/rux/rux.conf");
if ruxconf.is_file() { if ruxconf.is_file() {
let pac = read_default().unwrap_or_else(|err| { let pac = read_default(ruxconf).unwrap_or_else(|err| {
println!("{:?}", err); eprintln!("{:?}", err);
std::process::exit(1) std::process::exit(1)
}); });
config.run(pac); config.run(pac);

View File

@ -1,4 +1,4 @@
use std::path::PathBuf; use std::path::{PathBuf, Path};
use std::io::BufReader; use std::io::BufReader;
use std::io::prelude::*; use std::io::prelude::*;
use std::fs::{self, File}; use std::fs::{self, File};
@ -33,7 +33,6 @@ impl<'a> PackageManager<'a> {
install: Some(vec!["pacmatic", "-S"]), install: Some(vec!["pacmatic", "-S"]),
uninstall: Some(vec!["pacmatic", "-R"]), uninstall: Some(vec!["pacmatic", "-R"]),
sup: Some(vec!["pacmatic", "-Syu"]), sup: Some(vec!["pacmatic", "-Syu"]),
//sup: Some(vec!["pacmatic", "-Sy", "-Su"]),
purge: Some(vec!["pacmatic", "-Rdns"]), purge: Some(vec!["pacmatic", "-Rdns"]),
upgrade: Some(vec!["pacmatic", "-Su"]), upgrade: Some(vec!["pacmatic", "-Su"]),
update: Some(vec!["pacmatic", "-Sy"]), update: Some(vec!["pacmatic", "-Sy"]),
@ -89,9 +88,7 @@ impl<'a> PackageManager<'a> {
exe: PathBuf::from("bin/xbps-install"), exe: PathBuf::from("bin/xbps-install"),
} }
} }
// Allows setting the default.conf // Allows setting the default in rux.conf
// TODO: put default.conf somewhere it actually belongs rather than in
// the current folder.
pub fn set_default(&self) -> std::io::Result<()> { pub fn set_default(&self) -> std::io::Result<()> {
let mut home = match env::home_dir() { let mut home = match env::home_dir() {
Some(path) => path, Some(path) => path,
@ -104,7 +101,6 @@ impl<'a> PackageManager<'a> {
fs::create_dir_all(&home).unwrap_or_else(|why| { fs::create_dir_all(&home).unwrap_or_else(|why| {
println!("! {:?}", why.kind()); println!("! {:?}", why.kind());
}); });
println!("{:?}", &home.display());
home.push("rux.conf"); home.push("rux.conf");
let mut file = File::create(home)?; let mut file = File::create(home)?;
file.write_all(self.name.as_bytes())?; file.write_all(self.name.as_bytes())?;
@ -124,14 +120,15 @@ impl<'a> PackageManager<'a> {
/// Pulls the first line out of the default.conf and loads that. /// Pulls the first line out of the default.conf and loads that.
/// If it doesn't recognize the file it will tell the user that there's an /// If it doesn't recognize the file it will tell the user that there's an
/// issue before exiting. /// issue before exiting.
// TODO: Have this delete malformed default.conf pub fn read_default<'a, P: AsRef<Path>>(ruxconf: P) -> Result<PackageManager<'a>, Box<Error>> {
pub fn read_default<'a>() -> Result<PackageManager<'a>, Box<Error>> { /*
let mut home = env::home_dir().unwrap_or_else(|| { let mut home = env::home_dir().unwrap_or_else(|| {
eprintln!("Cannot load file, home directory cannot be found"); eprintln!("Cannot load file, home directory cannot be found");
std::process::exit(1) std::process::exit(1)
}); });
home.push(".config/rux/rux.conf"); home.push(".config/rux/rux.conf");
let file = File::open(&home)?; */
let file = File::open(&ruxconf)?;
let buffered = BufReader::new(file); let buffered = BufReader::new(file);
for line in buffered.lines() { for line in buffered.lines() {
match &*line.unwrap() { match &*line.unwrap() {
@ -140,9 +137,9 @@ pub fn read_default<'a>() -> Result<PackageManager<'a>, Box<Error>> {
"apt" => return Ok(PackageManager::apt()), "apt" => return Ok(PackageManager::apt()),
"xbps" => return Ok(PackageManager::xbps()), "xbps" => return Ok(PackageManager::xbps()),
_ => { _ => {
println!("Default either not set or has been changed"); eprintln!("Default either not set or has been changed");
std::fs::remove_file(home).unwrap_or_else(|err| { std::fs::remove_file(ruxconf).unwrap_or_else(|err| {
println!("Failed to delete: {:?}", err); eprintln!("Failed to delete: {:?}", err);
}); });
std::process::exit(1) std::process::exit(1)
} }