fix + test
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
JMARyA 2024-12-29 11:50:58 +01:00
parent 5763c8a1c4
commit 67c31725c1
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
4 changed files with 23 additions and 5 deletions

1
src/lib.rs Normal file
View file

@ -0,0 +1 @@
pub mod pkg;

View file

@ -9,11 +9,10 @@ use based::get_pg;
use based::page::{Shell, render_page};
use based::request::{RequestContext, StringResponse};
use maud::html;
use pkg::Repository;
use pacco::pkg::Repository;
use rocket::get;
use rocket::routes;
pub mod pkg;
pub mod routes;
#[get("/")]

View file

@ -27,6 +27,24 @@ impl Package {
}
/// Extract values from a package filename
///
/// # Example
///
/// ```
/// use pacco::pkg::Package;
///
/// let (name, version, rel, arch) = Package::extract_pkg_name("pkg-ver-rel-x86_64.pkg.tar.zst").unwrap();
/// assert_eq!(name, "pkg");
/// assert_eq!(version, "ver");
/// assert_eq!(rel, "rel");
/// assert_eq!(arch, pacco::pkg::arch::Architecture::x86_64);
///
/// let (name, version, rel, arch) = Package::extract_pkg_name("my-pkg-ver-rel-x86_64.pkg.tar.zst").unwrap();
/// assert_eq!(name, "my-pkg");
/// assert_eq!(version, "ver");
/// assert_eq!(rel, "rel");
/// assert_eq!(arch, pacco::pkg::arch::Architecture::x86_64);
/// ```
pub fn extract_pkg_name(file_name: &str) -> Option<(String, String, String, Architecture)> {
// Extract (assuming the filename is "<pkg_name>-<version>-<relation>-<arch>.pkg.tar.zst")
let mut splitted = file_name.split('-').collect::<Vec<&str>>();
@ -38,7 +56,7 @@ impl Package {
let relation = splitted.pop()?;
let version = splitted.pop()?;
let pkg_name = splitted.join(" ");
let pkg_name = splitted.join("-");
return Some((
pkg_name,

View file

@ -5,8 +5,8 @@ use rocket::tokio::io::AsyncReadExt;
use rocket::{FromForm, get, post};
use serde_json::json;
use crate::pkg::arch::Architecture;
use crate::pkg::{Package, Repository};
use pacco::pkg::arch::Architecture;
use pacco::pkg::{Package, Repository};
// /pkg/<repo>/<arch>/<pkg_name>
// /pkg/<repo>/<arch>/