From 235c582b76b759147b4fc7026254a674f830ae0e Mon Sep 17 00:00:00 2001 From: Ishaan Subramanya Date: Tue, 19 Mar 2024 09:05:40 +0530 Subject: [PATCH 01/11] created add_repo TODO verify provided link --- paxy/Cargo.toml | 1 + paxy/src/actions/mod.rs | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/paxy/Cargo.toml b/paxy/Cargo.toml index ff4cf83..1f26850 100644 --- a/paxy/Cargo.toml +++ b/paxy/Cargo.toml @@ -56,3 +56,4 @@ pollster = "0.3" reqwest = "0.11" url = { version = "2.3", features = ["serde"] } extism = "1.2.0" +csv = "1.3.0" diff --git a/paxy/src/actions/mod.rs b/paxy/src/actions/mod.rs index 2f29ebf..6a54fb3 100644 --- a/paxy/src/actions/mod.rs +++ b/paxy/src/actions/mod.rs @@ -40,6 +40,7 @@ pub mod list; pub mod search; pub mod uninstall; pub mod update; +pub mod add_repo; // endregion: MODULES @@ -59,3 +60,12 @@ pub use uninstall::*; pub use update::*; // endregion: RE-EXPORTS +#[macro_export] +macro_rules! home { + () => { + match home::home_dir() { + Some(path) => path, + None => panic!("Impossible to get your home dir!"), + } + }; +} \ No newline at end of file From cb14a781f6b012aa91cd6173b3bd4013b4726f0d Mon Sep 17 00:00:00 2001 From: Ishaan Subramanya Date: Tue, 19 Mar 2024 09:09:24 +0530 Subject: [PATCH 02/11] created add_repo TODO verify provided link --- paxy/src/actions/add_repo.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 paxy/src/actions/add_repo.rs diff --git a/paxy/src/actions/add_repo.rs b/paxy/src/actions/add_repo.rs new file mode 100644 index 0000000..25e1968 --- /dev/null +++ b/paxy/src/actions/add_repo.rs @@ -0,0 +1,13 @@ +use csv::Writer; + +use crate::home; + +// TODO verify if repo is real +fn add_repo(repo: &str) { + let mut file = home!(); + file.push(".paxy"); + file.push("repos.csv"); + let mut repos = Writer::from_path(file.as_path()).unwrap(); + repos.write_field(repo).unwrap(); + +} \ No newline at end of file From b4a2fcab00c7be7c792f9146ba88134a26c15391 Mon Sep 17 00:00:00 2001 From: Ishaan Subramanya Date: Tue, 19 Mar 2024 16:48:47 +0530 Subject: [PATCH 03/11] rewrote add_repo to use bson --- paxy/Cargo.toml | 2 +- paxy/src/actions/add_repo.rs | 14 +++++++------- paxy/src/actions/mod.rs | 1 + 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/paxy/Cargo.toml b/paxy/Cargo.toml index 1f26850..a420acf 100644 --- a/paxy/Cargo.toml +++ b/paxy/Cargo.toml @@ -56,4 +56,4 @@ pollster = "0.3" reqwest = "0.11" url = { version = "2.3", features = ["serde"] } extism = "1.2.0" -csv = "1.3.0" +bson = "2.9.0" diff --git a/paxy/src/actions/add_repo.rs b/paxy/src/actions/add_repo.rs index 25e1968..1675077 100644 --- a/paxy/src/actions/add_repo.rs +++ b/paxy/src/actions/add_repo.rs @@ -1,13 +1,13 @@ -use csv::Writer; +use std::fs::read_to_string; + +use bson::Document; use crate::home; -// TODO verify if repo is real -fn add_repo(repo: &str) { +fn add_repo(repo: String, name: String) { let mut file = home!(); file.push(".paxy"); - file.push("repos.csv"); - let mut repos = Writer::from_path(file.as_path()).unwrap(); - repos.write_field(repo).unwrap(); - + file.push("repos.bson"); + let mut doc = Document::from_reader(read_to_string(file).unwrap().as_bytes()).unwrap(); + doc.insert(name, repo); } \ No newline at end of file diff --git a/paxy/src/actions/mod.rs b/paxy/src/actions/mod.rs index 6a54fb3..099d36c 100644 --- a/paxy/src/actions/mod.rs +++ b/paxy/src/actions/mod.rs @@ -41,6 +41,7 @@ pub mod search; pub mod uninstall; pub mod update; pub mod add_repo; +pub mod rm_repo; // endregion: MODULES From 1e31778020aead65981c47c4771a15e222cecb63 Mon Sep 17 00:00:00 2001 From: Ishaan Subramanya Date: Sun, 24 Mar 2024 21:26:19 +0530 Subject: [PATCH 04/11] merged main --- paxy/src/actions/rm_repo.rs | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 paxy/src/actions/rm_repo.rs diff --git a/paxy/src/actions/rm_repo.rs b/paxy/src/actions/rm_repo.rs new file mode 100644 index 0000000..e69de29 From ac4f78fdacf60d4759b3fd38aefa994d37512594 Mon Sep 17 00:00:00 2001 From: Ishaan Subramanya Date: Sun, 24 Mar 2024 21:26:57 +0530 Subject: [PATCH 05/11] updated gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8168ddf..d0879dd 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ # will have compiled files and executables debug/ target/ +podman-target/ # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html From e863f41a151c43bb6d1b32dcf39a591d62245bf5 Mon Sep 17 00:00:00 2001 From: Ishaan S Date: Wed, 20 Mar 2024 14:21:38 +0530 Subject: [PATCH 06/11] added pkg-config --- Containerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Containerfile b/Containerfile index 814d470..250c6a6 100644 --- a/Containerfile +++ b/Containerfile @@ -6,4 +6,4 @@ RUN pacman -Sy --noconfirm rustup cargo RUN rustup self upgrade-data RUN rustup default nightly-2024-03-17 # Project dependencies -RUN pacman -S --noconfirm gdk-pixbuf2 pango gtk4 pkg-config +RUN pacman -S --noconfirm gdk-pixbuf2 pango gtk4 pkg-config \ No newline at end of file From a73fc5345a1545c20a0f9380272ddbbbf9e94260 Mon Sep 17 00:00:00 2001 From: Ishaan Subramanya Date: Sun, 24 Mar 2024 21:22:20 +0530 Subject: [PATCH 07/11] built add_repo --- .gitignore | 3 ++- Containerfile | 10 +++++-- paxy/Cargo.toml | 1 + paxy/src/actions/add_repo.rs | 52 ++++++++++++++++++++++++++++++++---- paxy/src/actions/mod.rs | 20 ++++++++++++-- paxy/src/actions/rm_repo.rs | 1 + paxy/src/data/manifest.rs | 47 -------------------------------- paxy/src/data/mod.rs | 1 - 8 files changed, 77 insertions(+), 58 deletions(-) delete mode 100644 paxy/src/data/manifest.rs diff --git a/.gitignore b/.gitignore index d0879dd..7e9708a 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ Cargo.lock # Visual Studio Code *.code-workspace +/.vscode .vscode/* !.vscode/settings.json !.vscode/tasks.json @@ -32,4 +33,4 @@ Cargo.lock /packaging/**/*.tar.* /packaging/**/*.pack /packaging/paxy-git/paxy/* -/packaging/paxy/paxy/* +/packaging/paxy/paxy/* \ No newline at end of file diff --git a/Containerfile b/Containerfile index 250c6a6..ec8f6af 100644 --- a/Containerfile +++ b/Containerfile @@ -1,9 +1,15 @@ FROM archlinux:latest +ENV RUSTC_WRAPPER=/root/.cargo/bin/sccache +ENV CARGO_INCREMENTAL=0 +ENV CARGO_TARGET_DIR=/paxy/target + # Install Rust RUN pacman -Sy --noconfirm rustup cargo # Toolchain setup -RUN rustup self upgrade-data +RUN /usr/bin/rustup self upgrade-data RUN rustup default nightly-2024-03-17 # Project dependencies -RUN pacman -S --noconfirm gdk-pixbuf2 pango gtk4 pkg-config \ No newline at end of file +RUN pacman -S --noconfirm gdk-pixbuf2 pango gtk4 pkg-config +# Extras +RUN pacman -S --noconfirm sccache \ No newline at end of file diff --git a/paxy/Cargo.toml b/paxy/Cargo.toml index a420acf..1af4864 100644 --- a/paxy/Cargo.toml +++ b/paxy/Cargo.toml @@ -57,3 +57,4 @@ reqwest = "0.11" url = { version = "2.3", features = ["serde"] } extism = "1.2.0" bson = "2.9.0" +git2 = {version = "0.18.3", default-features = false, features = ["https"]} diff --git a/paxy/src/actions/add_repo.rs b/paxy/src/actions/add_repo.rs index 1675077..2d2f427 100644 --- a/paxy/src/actions/add_repo.rs +++ b/paxy/src/actions/add_repo.rs @@ -1,13 +1,55 @@ -use std::fs::read_to_string; +use std::fs::{create_dir, create_dir_all, read, read_to_string, write, File}; -use bson::Document; +use bson::{doc, Document}; +use git2::Repository; +use log::{info, warn}; -use crate::home; +use crate::{ensure_path, home}; -fn add_repo(repo: String, name: String) { +fn add_repo(repo: &str, name: &str) { let mut file = home!(); file.push(".paxy"); + ensure_path!(); file.push("repos.bson"); - let mut doc = Document::from_reader(read_to_string(file).unwrap().as_bytes()).unwrap(); + let mut doc = if !file.is_file() { + warn!("file not found. Creating"); + let doc = doc! {"paxy-official": "https://github.com/Pax-Hub/paxy-pkg-repository.git"}; + let mut buf = vec![]; + doc.to_writer(&mut buf).unwrap(); + write(file.clone(), buf).unwrap(); + doc + } else { + info!("Reading from pre-exisiting file"); + Document::from_reader( + File::open(file.clone()).unwrap() + ) + .unwrap() + }; doc.insert(name, repo); + let mut buf = vec![]; + doc.to_writer(&mut buf).unwrap(); + write(file.clone(), buf).unwrap(); + file.pop(); + file.push("repos"); + file.push(name); + ensure_path!(file); + Repository::clone(repo, file).unwrap(); +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn add_repo_norm_test() { + add_repo("https://github.com/Pax-Hub/paxy-pkg-repository.git", "paxy"); + let mut file = home!(); + file.push(".paxy"); + file.push("repos.bson"); + let doc = Document::from_reader( + File::open(file.clone()).unwrap() + ) + .unwrap(); + assert_eq!(doc, doc! {"paxy-official": "https://github.com/Pax-Hub/paxy-pkg-repository.git", "paxy": "https://github.com/Pax-Hub/paxy-pkg-repository.git"}); + } } \ No newline at end of file diff --git a/paxy/src/actions/mod.rs b/paxy/src/actions/mod.rs index 099d36c..c43b163 100644 --- a/paxy/src/actions/mod.rs +++ b/paxy/src/actions/mod.rs @@ -34,14 +34,14 @@ use snafu::Snafu; // region: MODULES +pub mod add_repo; pub mod downgrade; pub mod install; pub mod list; +pub mod rm_repo; pub mod search; pub mod uninstall; pub mod update; -pub mod add_repo; -pub mod rm_repo; // endregion: MODULES @@ -69,4 +69,20 @@ macro_rules! home { None => panic!("Impossible to get your home dir!"), } }; +} + +#[macro_export] +macro_rules! ensure_path { + () => { + let mut file = home!(); + file.push(".paxy"); + if !file.is_dir() { + ::std::fs::create_dir_all(file).expect("Inufficient permissions"); + } + }; + ($path:ident) => { + if !$path.is_dir() { + ::std::fs::create_dir_all($path.clone()).expect("Inufficient permissions"); + } + } } \ No newline at end of file diff --git a/paxy/src/actions/rm_repo.rs b/paxy/src/actions/rm_repo.rs index e69de29..8b13789 100644 --- a/paxy/src/actions/rm_repo.rs +++ b/paxy/src/actions/rm_repo.rs @@ -0,0 +1 @@ + diff --git a/paxy/src/data/manifest.rs b/paxy/src/data/manifest.rs deleted file mode 100644 index 45257fc..0000000 --- a/paxy/src/data/manifest.rs +++ /dev/null @@ -1,47 +0,0 @@ -use std::{fs, path::Path}; - -use serde::{Deserialize, Serialize}; -use url::Url; - -#[derive(Debug, Serialize, Deserialize, PartialEq)] -struct Manifest { - version: Vec, - author: Option, - name: String, -} - -#[derive(Debug, Serialize, Deserialize, PartialEq)] -struct Version { - url: Url, - number: String, -} - -#[allow(dead_code)] -fn parse_manifest(manifest: Box) -> Manifest { - let toml = fs::read_to_string(manifest).unwrap(); - toml::from_str(&toml).unwrap() -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn parse_normal() { - let toml = r#"name = "paxy" -[[version]] -url = "https://github.com/tizonia/tizonia-openmax-il" -number = "1.0.0""#; - assert_eq!( - toml::from_str::(toml).unwrap(), - Manifest { - version: vec![Version { - url: Url::parse("https://github.com/tizonia/tizonia-openmax-il").unwrap(), - number: "1.0.0".to_string() - }], - name: "paxy".to_string(), - author: None - } - ); - } -} diff --git a/paxy/src/data/mod.rs b/paxy/src/data/mod.rs index e9003cc..68a6538 100644 --- a/paxy/src/data/mod.rs +++ b/paxy/src/data/mod.rs @@ -36,4 +36,3 @@ use snafu::Snafu; // endregion: RE-EXPORTS mod config; -mod manifest; From 10ecb62445ba4eb6c240e92288b6ada808c73c57 Mon Sep 17 00:00:00 2001 From: Ishaan Subramanya Date: Sun, 24 Mar 2024 21:23:57 +0530 Subject: [PATCH 08/11] fmt and ignore --- paxy/src/actions/add_repo.rs | 26 +++++++++++++------------- paxy/src/actions/mod.rs | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/paxy/src/actions/add_repo.rs b/paxy/src/actions/add_repo.rs index 2d2f427..346137e 100644 --- a/paxy/src/actions/add_repo.rs +++ b/paxy/src/actions/add_repo.rs @@ -1,4 +1,4 @@ -use std::fs::{create_dir, create_dir_all, read, read_to_string, write, File}; +use std::fs::{write, File}; use bson::{doc, Document}; use git2::Repository; @@ -6,6 +6,7 @@ use log::{info, warn}; use crate::{ensure_path, home}; +#[allow(unused)] fn add_repo(repo: &str, name: &str) { let mut file = home!(); file.push(".paxy"); @@ -15,19 +16,18 @@ fn add_repo(repo: &str, name: &str) { warn!("file not found. Creating"); let doc = doc! {"paxy-official": "https://github.com/Pax-Hub/paxy-pkg-repository.git"}; let mut buf = vec![]; - doc.to_writer(&mut buf).unwrap(); + doc.to_writer(&mut buf) + .unwrap(); write(file.clone(), buf).unwrap(); doc } else { info!("Reading from pre-exisiting file"); - Document::from_reader( - File::open(file.clone()).unwrap() - ) - .unwrap() + Document::from_reader(File::open(file.clone()).unwrap()).unwrap() }; doc.insert(name, repo); let mut buf = vec![]; - doc.to_writer(&mut buf).unwrap(); + doc.to_writer(&mut buf) + .unwrap(); write(file.clone(), buf).unwrap(); file.pop(); file.push("repos"); @@ -46,10 +46,10 @@ mod tests { let mut file = home!(); file.push(".paxy"); file.push("repos.bson"); - let doc = Document::from_reader( - File::open(file.clone()).unwrap() - ) - .unwrap(); - assert_eq!(doc, doc! {"paxy-official": "https://github.com/Pax-Hub/paxy-pkg-repository.git", "paxy": "https://github.com/Pax-Hub/paxy-pkg-repository.git"}); + let doc = Document::from_reader(File::open(file.clone()).unwrap()).unwrap(); + assert_eq!( + doc, + doc! {"paxy-official": "https://github.com/Pax-Hub/paxy-pkg-repository.git", "paxy": "https://github.com/Pax-Hub/paxy-pkg-repository.git"} + ); } -} \ No newline at end of file +} diff --git a/paxy/src/actions/mod.rs b/paxy/src/actions/mod.rs index c43b163..5eb0b2a 100644 --- a/paxy/src/actions/mod.rs +++ b/paxy/src/actions/mod.rs @@ -84,5 +84,5 @@ macro_rules! ensure_path { if !$path.is_dir() { ::std::fs::create_dir_all($path.clone()).expect("Inufficient permissions"); } - } -} \ No newline at end of file + }; +} From 28ff58a0c30df887ac7ac7a7ae570b9bf99f999c Mon Sep 17 00:00:00 2001 From: Ishaan Subramanya Date: Sun, 24 Mar 2024 21:47:19 +0530 Subject: [PATCH 09/11] updated podman cargo target dir --- Containerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Containerfile b/Containerfile index ec8f6af..dfd3e61 100644 --- a/Containerfile +++ b/Containerfile @@ -2,7 +2,7 @@ FROM archlinux:latest ENV RUSTC_WRAPPER=/root/.cargo/bin/sccache ENV CARGO_INCREMENTAL=0 -ENV CARGO_TARGET_DIR=/paxy/target +ENV CARGO_TARGET_DIR=/paxy/podman-target # Install Rust RUN pacman -Sy --noconfirm rustup cargo From 7a97c43405c45ac22eec238eb9be933f162e1189 Mon Sep 17 00:00:00 2001 From: Ishaan Subramanya Date: Sun, 24 Mar 2024 22:06:03 +0530 Subject: [PATCH 10/11] switched ensure_path to a function --- paxy/src/actions/add_repo.rs | 6 +++--- paxy/src/actions/mod.rs | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/paxy/src/actions/add_repo.rs b/paxy/src/actions/add_repo.rs index 346137e..4e28462 100644 --- a/paxy/src/actions/add_repo.rs +++ b/paxy/src/actions/add_repo.rs @@ -4,13 +4,13 @@ use bson::{doc, Document}; use git2::Repository; use log::{info, warn}; -use crate::{ensure_path, home}; +use crate::{actions::ensure_path, home}; #[allow(unused)] fn add_repo(repo: &str, name: &str) { let mut file = home!(); file.push(".paxy"); - ensure_path!(); + ensure_path(None); file.push("repos.bson"); let mut doc = if !file.is_file() { warn!("file not found. Creating"); @@ -32,7 +32,7 @@ fn add_repo(repo: &str, name: &str) { file.pop(); file.push("repos"); file.push(name); - ensure_path!(file); + ensure_path(Some(&file)); Repository::clone(repo, file).unwrap(); } diff --git a/paxy/src/actions/mod.rs b/paxy/src/actions/mod.rs index 5eb0b2a..2b7b616 100644 --- a/paxy/src/actions/mod.rs +++ b/paxy/src/actions/mod.rs @@ -28,6 +28,8 @@ pub enum Error { // region: IMPORTS +use std::path::PathBuf; + use snafu::Snafu; // endregion: IMPORTS @@ -71,18 +73,17 @@ macro_rules! home { }; } -#[macro_export] -macro_rules! ensure_path { - () => { +#[inline] +pub fn ensure_path(path: Option<&PathBuf>) { + if path.is_none() { let mut file = home!(); file.push(".paxy"); if !file.is_dir() { ::std::fs::create_dir_all(file).expect("Inufficient permissions"); } - }; - ($path:ident) => { - if !$path.is_dir() { - ::std::fs::create_dir_all($path.clone()).expect("Inufficient permissions"); + } else { + if !path.unwrap().is_dir() { + ::std::fs::create_dir_all(path.unwrap().clone()).expect("Inufficient permissions"); } - }; -} + } +} \ No newline at end of file From 3bab1565292b52d8f8c74629c5aa79b3ff48c4d8 Mon Sep 17 00:00:00 2001 From: Ishaan Subramanya Date: Sun, 24 Mar 2024 22:09:41 +0530 Subject: [PATCH 11/11] fmt --- paxy/src/actions/mod.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/paxy/src/actions/mod.rs b/paxy/src/actions/mod.rs index 2b7b616..ce4fff0 100644 --- a/paxy/src/actions/mod.rs +++ b/paxy/src/actions/mod.rs @@ -82,8 +82,15 @@ pub fn ensure_path(path: Option<&PathBuf>) { ::std::fs::create_dir_all(file).expect("Inufficient permissions"); } } else { - if !path.unwrap().is_dir() { - ::std::fs::create_dir_all(path.unwrap().clone()).expect("Inufficient permissions"); + if !path + .unwrap() + .is_dir() + { + ::std::fs::create_dir_all( + path.unwrap() + .clone(), + ) + .expect("Inufficient permissions"); } } -} \ No newline at end of file +}