feat(server): improve package parse semantics

repo-db
Jef Roosens 2023-08-01 13:54:26 +02:00
parent a2d844c582
commit f706b72b7c
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
4 changed files with 69 additions and 32 deletions

39
Cargo.lock generated
View File

@ -407,8 +407,11 @@ checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5"
dependencies = [ dependencies = [
"android-tzdata", "android-tzdata",
"iana-time-zone", "iana-time-zone",
"js-sys",
"num-traits", "num-traits",
"serde", "serde",
"time 0.1.45",
"wasm-bindgen",
"winapi", "winapi",
] ]
@ -774,7 +777,7 @@ checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"libc", "libc",
"wasi", "wasi 0.11.0+wasi-snapshot-preview1",
] ]
[[package]] [[package]]
@ -1194,7 +1197,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2"
dependencies = [ dependencies = [
"libc", "libc",
"wasi", "wasi 0.11.0+wasi-snapshot-preview1",
"windows-sys", "windows-sys",
] ]
@ -1624,6 +1627,7 @@ name = "rieterd"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"axum", "axum",
"chrono",
"clap", "clap",
"futures", "futures",
"libarchive", "libarchive",
@ -1834,7 +1838,7 @@ dependencies = [
"sqlx", "sqlx",
"strum", "strum",
"thiserror", "thiserror",
"time", "time 0.3.23",
"tracing", "tracing",
"url", "url",
"uuid", "uuid",
@ -1902,7 +1906,7 @@ dependencies = [
"rust_decimal", "rust_decimal",
"sea-query-derive", "sea-query-derive",
"serde_json", "serde_json",
"time", "time 0.3.23",
"uuid", "uuid",
] ]
@ -1918,7 +1922,7 @@ dependencies = [
"sea-query", "sea-query",
"serde_json", "serde_json",
"sqlx", "sqlx",
"time", "time 0.3.23",
"uuid", "uuid",
] ]
@ -2196,7 +2200,7 @@ dependencies = [
"smallvec", "smallvec",
"sqlformat", "sqlformat",
"thiserror", "thiserror",
"time", "time 0.3.23",
"tokio", "tokio",
"tokio-stream", "tokio-stream",
"tracing", "tracing",
@ -2285,7 +2289,7 @@ dependencies = [
"sqlx-core", "sqlx-core",
"stringprep", "stringprep",
"thiserror", "thiserror",
"time", "time 0.3.23",
"tracing", "tracing",
"uuid", "uuid",
"whoami", "whoami",
@ -2330,7 +2334,7 @@ dependencies = [
"sqlx-core", "sqlx-core",
"stringprep", "stringprep",
"thiserror", "thiserror",
"time", "time 0.3.23",
"tracing", "tracing",
"uuid", "uuid",
"whoami", "whoami",
@ -2355,7 +2359,7 @@ dependencies = [
"percent-encoding", "percent-encoding",
"serde", "serde",
"sqlx-core", "sqlx-core",
"time", "time 0.3.23",
"tracing", "tracing",
"url", "url",
"uuid", "uuid",
@ -2472,6 +2476,17 @@ dependencies = [
"once_cell", "once_cell",
] ]
[[package]]
name = "time"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a"
dependencies = [
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
"winapi",
]
[[package]] [[package]]
name = "time" name = "time"
version = "0.3.23" version = "0.3.23"
@ -2809,6 +2824,12 @@ dependencies = [
"try-lock", "try-lock",
] ]
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.11.0+wasi-snapshot-preview1" version = "0.11.0+wasi-snapshot-preview1"

View File

@ -8,6 +8,7 @@ authors = ["Jef Roosens"]
[dependencies] [dependencies]
axum = { version = "0.6.18", features = ["http2"] } axum = { version = "0.6.18", features = ["http2"] }
chrono = { version = "0.4.26", features = ["serde"] }
clap = { version = "4.3.12", features = ["env", "derive"] } clap = { version = "4.3.12", features = ["env", "derive"] }
futures = "0.3.28" futures = "0.3.28"
libarchive = { path = "../libarchive" } libarchive = { path = "../libarchive" }

View File

@ -47,7 +47,7 @@ impl MigrationTrait for Migration {
.col(ColumnDef::new(Package::CSize).big_integer().not_null()) .col(ColumnDef::new(Package::CSize).big_integer().not_null())
.col(ColumnDef::new(Package::Description).string()) .col(ColumnDef::new(Package::Description).string())
.col(ColumnDef::new(Package::Url).string_len(255)) .col(ColumnDef::new(Package::Url).string_len(255))
.col(ColumnDef::new(Package::BuildDate).date_time()) .col(ColumnDef::new(Package::BuildDate).date_time().not_null())
.col(ColumnDef::new(Package::Packager).string_len(255)) .col(ColumnDef::new(Package::Packager).string_len(255))
.col(ColumnDef::new(Package::PgpSig).string_len(255)) .col(ColumnDef::new(Package::PgpSig).string_len(255))
.col(ColumnDef::new(Package::PgpSigSize).big_integer()) .col(ColumnDef::new(Package::PgpSigSize).big_integer())

View File

@ -1,3 +1,4 @@
use chrono::NaiveDateTime;
use libarchive::read::{Archive, Builder}; use libarchive::read::{Archive, Builder};
use libarchive::{Entry, ReadFilter}; use libarchive::{Entry, ReadFilter};
use std::fmt; use std::fmt;
@ -17,18 +18,18 @@ pub struct Package {
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct PkgInfo { pub struct PkgInfo {
pub name: String,
pub base: String, pub base: String,
pub name: String,
pub version: String, pub version: String,
pub description: String,
pub size: u64,
pub csize: u64,
pub url: String,
pub arch: String, pub arch: String,
pub build_date: i64, pub description: Option<String>,
pub packager: String, pub size: i64,
pub pgpsig: String, pub csize: i64,
pub pgpsigsize: i64, pub url: Option<String>,
pub build_date: NaiveDateTime,
pub packager: Option<String>,
pub pgpsig: Option<String>,
pub pgpsigsize: Option<i64>,
pub groups: Vec<String>, pub groups: Vec<String>,
pub licenses: Vec<String>, pub licenses: Vec<String>,
pub replaces: Vec<String>, pub replaces: Vec<String>,
@ -70,23 +71,27 @@ impl PkgInfo {
"pkgname" => self.name = value.to_string(), "pkgname" => self.name = value.to_string(),
"pkgbase" => self.base = value.to_string(), "pkgbase" => self.base = value.to_string(),
"pkgver" => self.version = value.to_string(), "pkgver" => self.version = value.to_string(),
"pkgdesc" => self.description = value.to_string(), "pkgdesc" => self.description = Some(value.to_string()),
"size" => { "size" => {
self.size = value.parse().map_err(|_| ParsePkgInfoError::InvalidSize)? self.size = value.parse().map_err(|_| ParsePkgInfoError::InvalidSize)?
} }
"url" => self.url = value.to_string(), "url" => self.url = Some(value.to_string()),
"arch" => self.arch = value.to_string(), "arch" => self.arch = value.to_string(),
"builddate" => { "builddate" => {
self.build_date = value let seconds: i64 = value
.parse() .parse()
.map_err(|_| ParsePkgInfoError::InvalidBuildDate)? .map_err(|_| ParsePkgInfoError::InvalidBuildDate)?;
self.build_date = NaiveDateTime::from_timestamp_millis(seconds * 1000)
.ok_or(ParsePkgInfoError::InvalidBuildDate)?
} }
"packager" => self.packager = value.to_string(), "packager" => self.packager = Some(value.to_string()),
"pgpsig" => self.pgpsig = value.to_string(), "pgpsig" => self.pgpsig = Some(value.to_string()),
"pgpsigsize" => { "pgpsigsize" => {
self.pgpsigsize = value self.pgpsigsize = Some(
.parse() value
.map_err(|_| ParsePkgInfoError::InvalidPgpSigSize)? .parse()
.map_err(|_| ParsePkgInfoError::InvalidPgpSigSize)?,
)
} }
"group" => self.groups.push(value.to_string()), "group" => self.groups.push(value.to_string()),
"license" => self.licenses.push(value.to_string()), "license" => self.licenses.push(value.to_string()),
@ -156,7 +161,8 @@ impl Package {
} }
if let Some(mut info) = info { if let Some(mut info) = info {
info.csize = fs::metadata(path.as_ref())?.len(); // I'll take my chances on a file size fitting in an i64
info.csize = fs::metadata(path.as_ref())?.len().try_into().unwrap();
Ok(Package { Ok(Package {
path: path.as_ref().to_path_buf(), path: path.as_ref().to_path_buf(),
@ -216,7 +222,10 @@ impl Package {
write("NAME", &info.name)?; write("NAME", &info.name)?;
write("BASE", &info.base)?; write("BASE", &info.base)?;
write("VERSION", &info.version)?; write("VERSION", &info.version)?;
write("DESC", &info.description)?;
if let Some(ref description) = info.description {
write("DESC", description)?;
}
write("GROUPS", &info.groups.join("\n"))?; write("GROUPS", &info.groups.join("\n"))?;
write("CSIZE", &info.csize.to_string())?; write("CSIZE", &info.csize.to_string())?;
write("ISIZE", &info.size.to_string())?; write("ISIZE", &info.size.to_string())?;
@ -225,11 +234,17 @@ impl Package {
write("SHA256SUM", checksum)?; write("SHA256SUM", checksum)?;
} }
write("URL", &info.url)?; if let Some(ref url) = info.url {
write("URL", url)?;
}
write("LICENSE", &info.licenses.join("\n"))?; write("LICENSE", &info.licenses.join("\n"))?;
write("ARCH", &info.arch)?; write("ARCH", &info.arch)?;
write("BUILDDATE", &info.build_date.to_string())?; write("BUILDDATE", &info.build_date.to_string())?;
write("PACKAGER", &info.packager)?;
if let Some(ref packager) = info.packager {
write("PACKAGER", packager)?;
}
write("REPLACES", &info.replaces.join("\n"))?; write("REPLACES", &info.replaces.join("\n"))?;
write("CONFLICTS", &info.conflicts.join("\n"))?; write("CONFLICTS", &info.conflicts.join("\n"))?;