feat(server): improve package parse semantics
parent
a2d844c582
commit
f706b72b7c
|
@ -407,8 +407,11 @@ checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5"
|
|||
dependencies = [
|
||||
"android-tzdata",
|
||||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-traits",
|
||||
"serde",
|
||||
"time 0.1.45",
|
||||
"wasm-bindgen",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
|
@ -774,7 +777,7 @@ checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
|
|||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
"wasi 0.11.0+wasi-snapshot-preview1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1194,7 +1197,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"wasi",
|
||||
"wasi 0.11.0+wasi-snapshot-preview1",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
|
@ -1624,6 +1627,7 @@ name = "rieterd"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"chrono",
|
||||
"clap",
|
||||
"futures",
|
||||
"libarchive",
|
||||
|
@ -1834,7 +1838,7 @@ dependencies = [
|
|||
"sqlx",
|
||||
"strum",
|
||||
"thiserror",
|
||||
"time",
|
||||
"time 0.3.23",
|
||||
"tracing",
|
||||
"url",
|
||||
"uuid",
|
||||
|
@ -1902,7 +1906,7 @@ dependencies = [
|
|||
"rust_decimal",
|
||||
"sea-query-derive",
|
||||
"serde_json",
|
||||
"time",
|
||||
"time 0.3.23",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
|
@ -1918,7 +1922,7 @@ dependencies = [
|
|||
"sea-query",
|
||||
"serde_json",
|
||||
"sqlx",
|
||||
"time",
|
||||
"time 0.3.23",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
|
@ -2196,7 +2200,7 @@ dependencies = [
|
|||
"smallvec",
|
||||
"sqlformat",
|
||||
"thiserror",
|
||||
"time",
|
||||
"time 0.3.23",
|
||||
"tokio",
|
||||
"tokio-stream",
|
||||
"tracing",
|
||||
|
@ -2285,7 +2289,7 @@ dependencies = [
|
|||
"sqlx-core",
|
||||
"stringprep",
|
||||
"thiserror",
|
||||
"time",
|
||||
"time 0.3.23",
|
||||
"tracing",
|
||||
"uuid",
|
||||
"whoami",
|
||||
|
@ -2330,7 +2334,7 @@ dependencies = [
|
|||
"sqlx-core",
|
||||
"stringprep",
|
||||
"thiserror",
|
||||
"time",
|
||||
"time 0.3.23",
|
||||
"tracing",
|
||||
"uuid",
|
||||
"whoami",
|
||||
|
@ -2355,7 +2359,7 @@ dependencies = [
|
|||
"percent-encoding",
|
||||
"serde",
|
||||
"sqlx-core",
|
||||
"time",
|
||||
"time 0.3.23",
|
||||
"tracing",
|
||||
"url",
|
||||
"uuid",
|
||||
|
@ -2472,6 +2476,17 @@ dependencies = [
|
|||
"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]]
|
||||
name = "time"
|
||||
version = "0.3.23"
|
||||
|
@ -2809,6 +2824,12 @@ dependencies = [
|
|||
"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]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
|
|
|
@ -8,6 +8,7 @@ authors = ["Jef Roosens"]
|
|||
|
||||
[dependencies]
|
||||
axum = { version = "0.6.18", features = ["http2"] }
|
||||
chrono = { version = "0.4.26", features = ["serde"] }
|
||||
clap = { version = "4.3.12", features = ["env", "derive"] }
|
||||
futures = "0.3.28"
|
||||
libarchive = { path = "../libarchive" }
|
||||
|
|
|
@ -47,7 +47,7 @@ impl MigrationTrait for Migration {
|
|||
.col(ColumnDef::new(Package::CSize).big_integer().not_null())
|
||||
.col(ColumnDef::new(Package::Description).string())
|
||||
.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::PgpSig).string_len(255))
|
||||
.col(ColumnDef::new(Package::PgpSigSize).big_integer())
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use chrono::NaiveDateTime;
|
||||
use libarchive::read::{Archive, Builder};
|
||||
use libarchive::{Entry, ReadFilter};
|
||||
use std::fmt;
|
||||
|
@ -17,18 +18,18 @@ pub struct Package {
|
|||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct PkgInfo {
|
||||
pub name: String,
|
||||
pub base: String,
|
||||
pub name: String,
|
||||
pub version: String,
|
||||
pub description: String,
|
||||
pub size: u64,
|
||||
pub csize: u64,
|
||||
pub url: String,
|
||||
pub arch: String,
|
||||
pub build_date: i64,
|
||||
pub packager: String,
|
||||
pub pgpsig: String,
|
||||
pub pgpsigsize: i64,
|
||||
pub description: Option<String>,
|
||||
pub size: i64,
|
||||
pub csize: 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 licenses: Vec<String>,
|
||||
pub replaces: Vec<String>,
|
||||
|
@ -70,23 +71,27 @@ impl PkgInfo {
|
|||
"pkgname" => self.name = value.to_string(),
|
||||
"pkgbase" => self.base = value.to_string(),
|
||||
"pkgver" => self.version = value.to_string(),
|
||||
"pkgdesc" => self.description = value.to_string(),
|
||||
"pkgdesc" => self.description = Some(value.to_string()),
|
||||
"size" => {
|
||||
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(),
|
||||
"builddate" => {
|
||||
self.build_date = value
|
||||
let seconds: i64 = value
|
||||
.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(),
|
||||
"pgpsig" => self.pgpsig = value.to_string(),
|
||||
"packager" => self.packager = Some(value.to_string()),
|
||||
"pgpsig" => self.pgpsig = Some(value.to_string()),
|
||||
"pgpsigsize" => {
|
||||
self.pgpsigsize = value
|
||||
.parse()
|
||||
.map_err(|_| ParsePkgInfoError::InvalidPgpSigSize)?
|
||||
self.pgpsigsize = Some(
|
||||
value
|
||||
.parse()
|
||||
.map_err(|_| ParsePkgInfoError::InvalidPgpSigSize)?,
|
||||
)
|
||||
}
|
||||
"group" => self.groups.push(value.to_string()),
|
||||
"license" => self.licenses.push(value.to_string()),
|
||||
|
@ -156,7 +161,8 @@ impl Package {
|
|||
}
|
||||
|
||||
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 {
|
||||
path: path.as_ref().to_path_buf(),
|
||||
|
@ -216,7 +222,10 @@ impl Package {
|
|||
write("NAME", &info.name)?;
|
||||
write("BASE", &info.base)?;
|
||||
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("CSIZE", &info.csize.to_string())?;
|
||||
write("ISIZE", &info.size.to_string())?;
|
||||
|
@ -225,11 +234,17 @@ impl Package {
|
|||
write("SHA256SUM", checksum)?;
|
||||
}
|
||||
|
||||
write("URL", &info.url)?;
|
||||
if let Some(ref url) = info.url {
|
||||
write("URL", url)?;
|
||||
}
|
||||
|
||||
write("LICENSE", &info.licenses.join("\n"))?;
|
||||
write("ARCH", &info.arch)?;
|
||||
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("CONFLICTS", &info.conflicts.join("\n"))?;
|
||||
|
|
Loading…
Reference in New Issue