Skip to content

Commit

Permalink
Add repo command completed (#12)
Browse files Browse the repository at this point in the history
* created add_repo TODO verify provided link

* created add_repo TODO verify provided link

* rewrote add_repo to use bson

* merged main

* updated gitignore

* added pkg-config

* built add_repo

* fmt and ignore

* updated podman cargo target dir

* switched ensure_path to a function

* fmt
  • Loading branch information
FerrisWasTaken authored Mar 24, 2024
1 parent 0f9e021 commit 036b1b5
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 50 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,6 16,7 @@ Cargo.lock

# Visual Studio Code
*.code-workspace
/.vscode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
Expand All @@ -31,4 33,4 @@ Cargo.lock
/packaging/**/*.tar.*
/packaging/**/*.pack
/packaging/paxy-git/paxy/*
/packaging/paxy/paxy/*
/packaging/paxy/paxy/*
8 changes: 7 additions & 1 deletion Containerfile
Original file line number Diff line number Diff line change
@@ -1,9 1,15 @@
FROM archlinux:latest

ENV RUSTC_WRAPPER=/root/.cargo/bin/sccache
ENV CARGO_INCREMENTAL=0
ENV CARGO_TARGET_DIR=/paxy/podman-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
# Extras
RUN pacman -S --noconfirm sccache
2 changes: 2 additions & 0 deletions paxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 56,5 @@ pollster = "0.3"
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"]}
55 changes: 55 additions & 0 deletions paxy/src/actions/add_repo.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,55 @@
use std::fs::{write, File};

use bson::{doc, Document};
use git2::Repository;
use log::{info, warn};

use crate::{actions::ensure_path, home};

#[allow(unused)]
fn add_repo(repo: &str, name: &str) {
let mut file = home!();
file.push(".paxy");
ensure_path(None);
file.push("repos.bson");
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(Some(&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"}
);
}
}
35 changes: 35 additions & 0 deletions paxy/src/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 28,19 @@ pub enum Error {

// region: IMPORTS

use std::path::PathBuf;

use snafu::Snafu;

// endregion: IMPORTS

// 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;
Expand All @@ -59,3 63,34 @@ 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!"),
}
};
}

#[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");
}
} else {
if !path
.unwrap()
.is_dir()
{
::std::fs::create_dir_all(
path.unwrap()
.clone(),
)
.expect("Inufficient permissions");
}
}
}
1 change: 1 addition & 0 deletions paxy/src/actions/rm_repo.rs
Original file line number Diff line number Diff line change
@@ -0,0 1 @@

47 changes: 0 additions & 47 deletions paxy/src/data/manifest.rs

This file was deleted.

1 change: 0 additions & 1 deletion paxy/src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 36,3 @@ use snafu::Snafu;

// endregion: RE-EXPORTS
mod config;
mod manifest;

0 comments on commit 036b1b5

Please sign in to comment.