feat(server): improve package parse semantics
This commit is contained in:
parent
a2d844c582
commit
f706b72b7c
4 changed files with 69 additions and 32 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue