parsing packages, and find_package_in_repositories done ( i gotta commit more often lmao)

This commit is contained in:
Lilly Rosaline 2022-02-13 12:44:53 -06:00
parent f2e78523ea
commit fed7106c20
11 changed files with 111 additions and 54 deletions

53
Cargo.lock generated
View file

@ -207,6 +207,21 @@ dependencies = [
"winapi",
]
[[package]]
name = "futures"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e"
dependencies = [
"futures-channel",
"futures-core",
"futures-executor",
"futures-io",
"futures-sink",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-channel"
version = "0.3.21"
@ -214,6 +229,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010"
dependencies = [
"futures-core",
"futures-sink",
]
[[package]]
@ -222,6 +238,34 @@ version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3"
[[package]]
name = "futures-executor"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6"
dependencies = [
"futures-core",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-io"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b"
[[package]]
name = "futures-macro"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "futures-sink"
version = "0.3.21"
@ -240,10 +284,16 @@ version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a"
dependencies = [
"futures-channel",
"futures-core",
"futures-io",
"futures-macro",
"futures-sink",
"futures-task",
"memchr",
"pin-project-lite",
"pin-utils",
"slab",
]
[[package]]
@ -256,10 +306,11 @@ dependencies = [
]
[[package]]
name = "gaybsd_package_manager"
name = "gaypk"
version = "0.1.0"
dependencies = [
"clap",
"futures",
"meowhash",
"reqwest",
"serde",

View file

@ -1,6 +1,6 @@
cargo-features = ["strip"]
[package]
name = "gaybsd_package_manager"
name = "gaypk"
description = "GayBSD Package Manager"
version = "0.1.0"
edition = "2021"
@ -15,6 +15,7 @@ sled = "0.34.7"
toml = "0.5.8"
serde_derive = "1.0.136"
serde = "1.0.136"
futures = "0.3.21"
[profile.release]
strip = true
opt-level = "z"

View file

@ -1,14 +1,20 @@
mf-version = 100
gaypk-version = 100
name = "example-package"
version = 100
key = ""
[files]
"/opt/etc" = { match = "etc/*", tracked = false }
"/opt/etc/enby/manuals" = { path = "manual.gmi", name = "example-package.gmi"}
"/opt/bin" = { file = "example-package.x86-64.elf", name = "example-package", bin = "x86-64-elf"}
version = "1.0.0"
revision = 0
pubkey = ""
scripts=["*.gpksh"]
exclude=["scripts", "*.gpksh"]
[dependencies]
# GayPK doesn't care about this stuff
[locale.en_US]
name = "Example Package"
description = "Example Package for testing GayPackage format."
[locale.tp_XW]
name = ""
description = ""
description = ""
[launcher]
category = "system"
launch = "terminal"
binary = "/opt/bin/example-package"

View file

@ -1 +0,0 @@
Hello world!

View file

@ -0,0 +1,4 @@
#!/usr/bin/env fish
# shellcheck disable=SC2034
OVERWRITE=false
cat etc-file.txt >> /opt/etc/etc-file.txt

View file

@ -0,0 +1 @@
Hello world! (from GayPK)

View file

@ -6,14 +6,13 @@ mod repository;
mod install;
mod package;
use meowhash::*;
use reqwest::*;
use sled::*;
use clap::*;
use crate::repository::find_package_in_repositories;
fn main() {
let operation = std::env::args().nth(1).expect("too few arguments!");
let args: String = std::env::args().collect();
let package_data = crate::package::read_package(std::fs::read_to_string("example-package/Package.toml").expect("Failed to read file"));
dbg!(package_data);
match operation.as_str() {
"upgrade" | "u" => {
@ -23,9 +22,10 @@ fn main() {
} else {
let package_name = std::env::args().nth(2).expect("too few arguments!");
find_package_in_repositories(&package_name, None);
println!("Reading package list");
let package_list = sled::open("/var/gaypack/packages").expect("Failed to open package list");
if package_list.contains_key(package_name).expect("Unexpected error") {
if package_list.contains_key(&package_name).expect("Unexpected error") {
println!("Package was found in package list, checking for updates");
}
}

View file

@ -1,33 +1,19 @@
use toml::map::Map;
use toml::value::Table;
use toml::value::{Array, Table};
use serde_derive::Deserialize;
#[derive(Deserialize)]
/// Represents a Package.toml file.
#[derive(Deserialize, Debug)]
pub struct PackageData {
manifest_verison: u64,
name: String,
version: u64,
key: String,
files: Map<String, PackageFile>,
#[serde(rename(deserialize = "gaypk-version"))]
pub gaypk_version: u64,
pub name: String,
pub version: String,
pub revision: u64,
pub pubkey: String,
pub scripts: Array,
pub exclude: Array,
pub dependencies: Table
}
#[derive(Deserialize)]
pub struct PackageFile {
match_: Option<String>,
tracked: Option<bool>,
file: String,
folder: Option<bool>,
name: Option<String>,
bin: Option<String>
}
impl Default for PackageFile {
fn default() -> Self {
PackageFile {
match_: None,
tracked: Some(true),
file: "".to_string(),
folder: Some(false),
name: None,
bin: None
}
}
pub fn read_package(data: String) -> PackageData {
toml::from_str(data.as_str()).expect("Parse failed!")
}

View file

@ -1,23 +1,32 @@
use std::error::Error;
use std::fs::{File, OpenOptions};
use std::collections::HashMap;
use std::fs::File;
use std::io::BufRead;
use std::path::Path;
use futures::executor::block_on;
use reqwest::StatusCode;
use toml::toml;
pub async fn find_package_in_repositories(package: String, installed: Option<u64>) -> Vec<String> {
pub fn find_package_in_repositories(package: &str, installed: Option<u64>) -> Option<Vec<String>> {
let mut hits: Vec<String> = vec!();
let client = reqwest::Client::new();
let repo_file = File::open("/var/gaypack/repositories.list").expect("Failed to open repository list");
let mut candidates: HashMap<u64, String> = HashMap::new();
for repository in std::io::BufReader::new(repo_file).lines() {
let repository = repository.expect("Unexpected error"); // i find this line kinda funny for some reason
let resp = client.get(format!("{}/gaypack/{}/latest/Package.toml", repository, package)).send().await.unwrap();
let resp = block_on(client.get(format!("{}/gaypack/{}/latest/Package.toml", repository, package)).send()).expect("GET request failed");
let status = resp.status();
let text = block_on(resp.text()).expect("Failed to receive packet body");
if installed.is_some() {
let package_data: crate::package::PackageData = toml::from_str(resp.text().await.expect("Failed to read text").as_str()).expect("Failed to parse toml");
candidates.insert(installed.unwrap(), "installed".to_string());
}
if resp.status() == StatusCode::from_u16(200).unwrap() {
hits.push(repository);
let package_data = &crate::package::read_package(text);
dbg!(package_data);
if status == StatusCode::from_u16(200).unwrap() {
candidates.insert(package_data.revision, repository);
}
};
return hits;
let mut sorted: Vec<_> = candidates.iter().collect();
sorted.sort_by_key(|entry| entry.0);
for (_, repository) in sorted.iter() {
hits.push(repository.as_str().to_string());
}
return Some(hits);
}