-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Specified more values in toolchain file (#8)
* Specified more values in toolchain file * fixed clippy errors and suppressed the placeholders * fmt * fixed pre releease for aarch64-unknown-linux-gnu * implemented config loading. NOTE: need to specify non-linux systems * Update rust-toolchain.toml --------- Co-authored-by: shivanandvp <[email protected]>
- Loading branch information
1 parent
72b7a9d
commit 0f0c20d
Showing
7 changed files
with
76 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
[workspace] | ||
resolver = "1" | ||
members = [ | ||
"paxy", | ||
"paxy_build", "paxy_install", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,72 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use std::path::PathBuf; | ||
use std::{ | ||
fs::{self, create_dir_all, File}, io::Write, path::PathBuf | ||
}; | ||
use url::Url; | ||
|
||
#[derive(Default, Serialize, Deserialize)] | ||
#[derive(Serialize, Deserialize)] | ||
pub struct Config { | ||
pub repositories: Vec<Url>, | ||
pub system_install_location: Option<PathBuf>, | ||
pub user_install_location: Option<PathBuf>, | ||
pub default_install_type: Option<InstallType>, | ||
pub repositories: Option<Vec<Url>>, | ||
pub system_install_location: PathBuf, | ||
pub user_install_location: PathBuf, | ||
pub default_install_type: InstallType, | ||
} | ||
|
||
#[derive(Serialize, Deserialize)] | ||
impl Default for Config { | ||
fn default() -> Self { | ||
let mut user: PathBuf = match home::home_dir() { | ||
Some(path) => path, | ||
None => panic!("Impossible to get your home dir!"), | ||
}; | ||
user.push(".paxy"); | ||
user.push("pkgs"); | ||
let system = if cfg!(linux) { | ||
PathBuf::from("/") | ||
} else { | ||
PathBuf::from("") | ||
}; | ||
|
||
let conf = Config { | ||
repositories: Some(vec![ | ||
Url::parse("https://github.com/Pax-Hub/Packages.git").unwrap() | ||
]), | ||
user_install_location: user.clone(), // Not harmful since the value is dropped in the very next line | ||
system_install_location: system, | ||
default_install_type: InstallType::default(), | ||
}; | ||
if !user.is_dir() { | ||
create_dir_all(user.clone()).expect("No permission"); // Not harmful since the value is dropped in the soon | ||
user.pop(); | ||
user.push("config.ini"); | ||
if user.is_file() { | ||
fs::remove_file(user.clone()).unwrap(); | ||
} | ||
if !user.is_file() { | ||
let mut file = File::create(user).unwrap(); | ||
file.write_all(toml::to_string(&conf).unwrap().as_bytes()).expect("Permission error"); | ||
} | ||
} | ||
conf | ||
} | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Default)] | ||
pub enum InstallType { | ||
User, | ||
#[default] | ||
System, | ||
} | ||
|
||
#[allow(dead_code)] | ||
fn load_conf() -> Config { | ||
let mut conf_path: PathBuf = match home::home_dir() { | ||
Some(path) => path, | ||
None => panic!("Impossible to get your home dir!"), | ||
}; | ||
conf_path.push(".paxy"); | ||
conf_path.push("config.ini"); | ||
match toml::from_str::<Config>(fs::read_to_string(&conf_path).unwrap().as_str()) { | ||
Ok(val) => val, | ||
Err(_) => Config::default() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
pub mod package; | ||
pub mod package; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters