Compare commits
No commits in common. "b097a5ea877bb470244c388d627073e8302f9701" and "3435435726bebb95065a40c8a42f302567763776" have entirely different histories.
b097a5ea87
...
3435435726
14 changed files with 53 additions and 369 deletions
39
Cargo.lock
generated
39
Cargo.lock
generated
|
|
@ -407,11 +407,8 @@ 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",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -777,7 +774,7 @@ checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"libc",
|
"libc",
|
||||||
"wasi 0.11.0+wasi-snapshot-preview1",
|
"wasi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -1197,7 +1194,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2"
|
checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"wasi 0.11.0+wasi-snapshot-preview1",
|
"wasi",
|
||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -1627,7 +1624,6 @@ name = "rieterd"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"chrono",
|
|
||||||
"clap",
|
"clap",
|
||||||
"futures",
|
"futures",
|
||||||
"libarchive",
|
"libarchive",
|
||||||
|
|
@ -1838,7 +1834,7 @@ dependencies = [
|
||||||
"sqlx",
|
"sqlx",
|
||||||
"strum",
|
"strum",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"time 0.3.23",
|
"time",
|
||||||
"tracing",
|
"tracing",
|
||||||
"url",
|
"url",
|
||||||
"uuid",
|
"uuid",
|
||||||
|
|
@ -1906,7 +1902,7 @@ dependencies = [
|
||||||
"rust_decimal",
|
"rust_decimal",
|
||||||
"sea-query-derive",
|
"sea-query-derive",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"time 0.3.23",
|
"time",
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -1922,7 +1918,7 @@ dependencies = [
|
||||||
"sea-query",
|
"sea-query",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"sqlx",
|
"sqlx",
|
||||||
"time 0.3.23",
|
"time",
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -2200,7 +2196,7 @@ dependencies = [
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"sqlformat",
|
"sqlformat",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"time 0.3.23",
|
"time",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-stream",
|
"tokio-stream",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
|
@ -2289,7 +2285,7 @@ dependencies = [
|
||||||
"sqlx-core",
|
"sqlx-core",
|
||||||
"stringprep",
|
"stringprep",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"time 0.3.23",
|
"time",
|
||||||
"tracing",
|
"tracing",
|
||||||
"uuid",
|
"uuid",
|
||||||
"whoami",
|
"whoami",
|
||||||
|
|
@ -2334,7 +2330,7 @@ dependencies = [
|
||||||
"sqlx-core",
|
"sqlx-core",
|
||||||
"stringprep",
|
"stringprep",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"time 0.3.23",
|
"time",
|
||||||
"tracing",
|
"tracing",
|
||||||
"uuid",
|
"uuid",
|
||||||
"whoami",
|
"whoami",
|
||||||
|
|
@ -2359,7 +2355,7 @@ dependencies = [
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"serde",
|
"serde",
|
||||||
"sqlx-core",
|
"sqlx-core",
|
||||||
"time 0.3.23",
|
"time",
|
||||||
"tracing",
|
"tracing",
|
||||||
"url",
|
"url",
|
||||||
"uuid",
|
"uuid",
|
||||||
|
|
@ -2476,17 +2472,6 @@ 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"
|
||||||
|
|
@ -2824,12 +2809,6 @@ 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"
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,10 @@ 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" }
|
||||||
|
sea-orm = { version = "0.12.1", features = ["sqlx-sqlite", "runtime-tokio-rustls", "macros"] }
|
||||||
sea-orm-migration = "0.12.1"
|
sea-orm-migration = "0.12.1"
|
||||||
serde = { version = "1.0.178", features = ["derive"] }
|
serde = { version = "1.0.178", features = ["derive"] }
|
||||||
sha256 = "1.1.4"
|
sha256 = "1.1.4"
|
||||||
|
|
@ -22,13 +22,3 @@ tower-http = { version = "0.4.1", features = ["fs", "trace"] }
|
||||||
tracing = "0.1.37"
|
tracing = "0.1.37"
|
||||||
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
|
||||||
uuid = { version = "1.4.0", features = ["v4"] }
|
uuid = { version = "1.4.0", features = ["v4"] }
|
||||||
|
|
||||||
[dependencies.sea-orm]
|
|
||||||
version = "0.12.1"
|
|
||||||
features = [
|
|
||||||
"sqlx-sqlite",
|
|
||||||
"sqlx-postgres",
|
|
||||||
"runtime-tokio-rustls",
|
|
||||||
"macros",
|
|
||||||
"with-chrono"
|
|
||||||
]
|
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,12 @@ use sea_orm::PaginatorTrait;
|
||||||
|
|
||||||
use pagination::PaginatedResponse;
|
use pagination::PaginatedResponse;
|
||||||
|
|
||||||
use crate::db::entities::package;
|
|
||||||
use crate::db::entities::repo;
|
use crate::db::entities::repo;
|
||||||
|
|
||||||
pub fn router() -> Router<crate::Global> {
|
pub fn router() -> Router<crate::Global> {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/repos", get(get_repos))
|
.route("/repos", get(get_repos))
|
||||||
.route("/repos/:id", get(get_single_repo))
|
.route("/repos/:id", get(get_single_repo))
|
||||||
.route("/packages", get(get_packages))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_repos(
|
async fn get_repos(
|
||||||
|
|
@ -44,16 +42,3 @@ async fn get_single_repo(
|
||||||
|
|
||||||
Ok(Json(repo))
|
Ok(Json(repo))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_packages(
|
|
||||||
State(global): State<crate::Global>,
|
|
||||||
Query(pagination): Query<pagination::Query>,
|
|
||||||
) -> crate::Result<Json<PaginatedResponse<package::Model>>> {
|
|
||||||
let pkgs = package::Entity::find()
|
|
||||||
.order_by_asc(package::Column::Id)
|
|
||||||
.paginate(&global.db, pagination.per_page.unwrap_or(25))
|
|
||||||
.fetch_page(pagination.page.unwrap_or(1) - 1)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(Json(pagination.res(pkgs)))
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -48,9 +48,6 @@ impl Cli {
|
||||||
self.init_tracing();
|
self.init_tracing();
|
||||||
|
|
||||||
let db = crate::db::init("sqlite://test.db").await.unwrap();
|
let db = crate::db::init("sqlite://test.db").await.unwrap();
|
||||||
// let db = crate::db::init("postgres://rieter:rieter@localhost:5432/rieter")
|
|
||||||
// .await
|
|
||||||
// .unwrap();
|
|
||||||
|
|
||||||
let config = Config {
|
let config = Config {
|
||||||
repo_dir: self.repo_dir.clone(),
|
repo_dir: self.repo_dir.clone(),
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,4 @@
|
||||||
|
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
|
|
||||||
pub mod package;
|
|
||||||
pub mod package_license;
|
|
||||||
pub mod repo;
|
pub mod repo;
|
||||||
|
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
|
|
||||||
|
|
||||||
use sea_orm::entity::prelude::*;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
|
||||||
#[sea_orm(table_name = "package")]
|
|
||||||
pub struct Model {
|
|
||||||
#[sea_orm(primary_key)]
|
|
||||||
pub id: i32,
|
|
||||||
pub repo_id: i32,
|
|
||||||
pub base: String,
|
|
||||||
pub name: String,
|
|
||||||
pub version: String,
|
|
||||||
pub arch: String,
|
|
||||||
pub size: i64,
|
|
||||||
pub c_size: i64,
|
|
||||||
pub description: Option<String>,
|
|
||||||
pub url: Option<String>,
|
|
||||||
pub build_date: DateTime,
|
|
||||||
pub packager: Option<String>,
|
|
||||||
pub pgp_sig: Option<String>,
|
|
||||||
pub pgp_sig_size: Option<i64>,
|
|
||||||
pub sha256_sum: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {
|
|
||||||
#[sea_orm(has_many = "super::package_license::Entity")]
|
|
||||||
PackageLicense,
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::repo::Entity",
|
|
||||||
from = "Column::RepoId",
|
|
||||||
to = "super::repo::Column::Id",
|
|
||||||
on_update = "NoAction",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
Repo,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::package_license::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::PackageLicense.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::repo::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Repo.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
|
|
||||||
|
|
||||||
use sea_orm::entity::prelude::*;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
|
||||||
#[sea_orm(table_name = "package_license")]
|
|
||||||
pub struct Model {
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub package_id: i32,
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub value: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to = "super::package::Entity",
|
|
||||||
from = "Column::PackageId",
|
|
||||||
to = "super::package::Column::Id",
|
|
||||||
on_update = "NoAction",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
Package,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::package::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Package.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
|
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
|
||||||
|
|
||||||
pub use super::package::Entity as Package;
|
|
||||||
pub use super::package_license::Entity as PackageLicense;
|
|
||||||
pub use super::repo::Entity as Repo;
|
pub use super::repo::Entity as Repo;
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,18 @@
|
||||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
|
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
|
||||||
|
|
||||||
use sea_orm::entity::prelude::*;
|
use sea_orm::entity::prelude::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::Serialize;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize)]
|
||||||
#[sea_orm(table_name = "repo")]
|
#[sea_orm(table_name = "repo")]
|
||||||
pub struct Model {
|
pub struct Model {
|
||||||
#[sea_orm(primary_key)]
|
#[sea_orm(primary_key)]
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
#[sea_orm(unique)]
|
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
pub enum Relation {
|
pub enum Relation {}
|
||||||
#[sea_orm(has_many = "super::package::Entity")]
|
|
||||||
Package,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::package::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Package.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ impl MigrationName for Migration {
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl MigrationTrait for Migration {
|
impl MigrationTrait for Migration {
|
||||||
|
// Define how to apply this migration: Create the Bakery table.
|
||||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
manager
|
manager
|
||||||
.create_table(
|
.create_table(
|
||||||
|
|
@ -26,81 +27,11 @@ impl MigrationTrait for Migration {
|
||||||
.col(ColumnDef::new(Repo::Description).string())
|
.col(ColumnDef::new(Repo::Description).string())
|
||||||
.to_owned(),
|
.to_owned(),
|
||||||
)
|
)
|
||||||
.await?;
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(Package::Table)
|
|
||||||
.col(
|
|
||||||
ColumnDef::new(Package::Id)
|
|
||||||
.integer()
|
|
||||||
.not_null()
|
|
||||||
.auto_increment()
|
|
||||||
.primary_key(),
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(Package::RepoId).integer().not_null())
|
|
||||||
.col(ColumnDef::new(Package::Base).string_len(255).not_null())
|
|
||||||
.col(ColumnDef::new(Package::Name).string_len(255).not_null())
|
|
||||||
.col(ColumnDef::new(Package::Version).string_len(255).not_null())
|
|
||||||
.col(ColumnDef::new(Package::Arch).string_len(255).not_null())
|
|
||||||
.col(ColumnDef::new(Package::Size).big_integer().not_null())
|
|
||||||
.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().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())
|
|
||||||
.col(ColumnDef::new(Package::Sha256Sum).char_len(64).not_null())
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKey::create()
|
|
||||||
.name("fk-package-repo_id")
|
|
||||||
.from(Package::Table, Package::RepoId)
|
|
||||||
.to(Repo::Table, Repo::Id)
|
|
||||||
.on_delete(ForeignKeyAction::Cascade),
|
|
||||||
)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(PackageLicense::Table)
|
|
||||||
.col(
|
|
||||||
ColumnDef::new(PackageLicense::PackageId)
|
|
||||||
.integer()
|
|
||||||
.not_null(),
|
|
||||||
)
|
|
||||||
.col(
|
|
||||||
ColumnDef::new(PackageLicense::Value)
|
|
||||||
.string_len(255)
|
|
||||||
.not_null(),
|
|
||||||
)
|
|
||||||
.primary_key(
|
|
||||||
Index::create()
|
|
||||||
.col(PackageLicense::PackageId)
|
|
||||||
.col(PackageLicense::Value),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKey::create()
|
|
||||||
.name("fk-package_license-package_id")
|
|
||||||
.from(PackageLicense::Table, PackageLicense::PackageId)
|
|
||||||
.to(Package::Table, Package::Id)
|
|
||||||
.on_delete(ForeignKeyAction::Cascade),
|
|
||||||
)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define how to rollback this migration: Drop the Bakery table.
|
// Define how to rollback this migration: Drop the Bakery table.
|
||||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(PackageLicense::Table).to_owned())
|
|
||||||
.await?;
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(Package::Table).to_owned())
|
|
||||||
.await?;
|
|
||||||
manager
|
manager
|
||||||
.drop_table(Table::drop().table(Repo::Table).to_owned())
|
.drop_table(Table::drop().table(Repo::Table).to_owned())
|
||||||
.await
|
.await
|
||||||
|
|
@ -114,30 +45,3 @@ pub enum Repo {
|
||||||
Name,
|
Name,
|
||||||
Description,
|
Description,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum Package {
|
|
||||||
Table,
|
|
||||||
Id,
|
|
||||||
RepoId,
|
|
||||||
Name,
|
|
||||||
Base,
|
|
||||||
Version,
|
|
||||||
Description,
|
|
||||||
Size,
|
|
||||||
CSize,
|
|
||||||
Url,
|
|
||||||
Arch,
|
|
||||||
BuildDate,
|
|
||||||
Packager,
|
|
||||||
PgpSig,
|
|
||||||
PgpSigSize,
|
|
||||||
Sha256Sum,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum PackageLicense {
|
|
||||||
Table,
|
|
||||||
PackageId,
|
|
||||||
Value,
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
mod api;
|
mod api;
|
||||||
mod cli;
|
mod cli;
|
||||||
pub mod db;
|
mod db;
|
||||||
mod error;
|
mod error;
|
||||||
mod repo;
|
mod repo;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,12 +71,9 @@ impl RepoGroupManager {
|
||||||
ar_db.close().and(ar_files.close()).map_err(Into::into)
|
ar_db.close().and(ar_files.close()).map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_pkg_from_path<P: AsRef<Path>>(
|
pub fn add_pkg_from_path<P: AsRef<Path>>(&mut self, repo: &str, path: P) -> io::Result<()> {
|
||||||
&mut self,
|
let mut pkg = Package::open(&path)?;
|
||||||
repo: &str,
|
pkg.calculate_checksum()?;
|
||||||
path: P,
|
|
||||||
) -> io::Result<Package> {
|
|
||||||
let pkg = Package::open(&path)?;
|
|
||||||
|
|
||||||
let archs = self.add_pkg_in_repo(repo, &pkg)?;
|
let archs = self.add_pkg_in_repo(repo, &pkg)?;
|
||||||
|
|
||||||
|
|
@ -90,9 +87,7 @@ impl RepoGroupManager {
|
||||||
fs::hard_link(&path, dest_pkg_path)?;
|
fs::hard_link(&path, dest_pkg_path)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::remove_file(path)?;
|
fs::remove_file(path)
|
||||||
|
|
||||||
Ok(pkg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a package to the given repo, returning to what architectures the package was added.
|
/// Add a package to the given repo, returning to what architectures the package was added.
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,11 @@ mod package;
|
||||||
|
|
||||||
pub use manager::RepoGroupManager;
|
pub use manager::RepoGroupManager;
|
||||||
|
|
||||||
use crate::db::entities::{package as db_package, repo as db_repo};
|
|
||||||
use axum::extract::{BodyStream, Path, State};
|
use axum::extract::{BodyStream, Path, State};
|
||||||
use axum::http::StatusCode;
|
use axum::http::StatusCode;
|
||||||
use axum::routing::{delete, get_service, post};
|
use axum::routing::{delete, get_service, post};
|
||||||
use axum::Router;
|
use axum::Router;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter};
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::{fs, io::AsyncWriteExt};
|
use tokio::{fs, io::AsyncWriteExt};
|
||||||
use tower_http::services::ServeDir;
|
use tower_http::services::ServeDir;
|
||||||
|
|
@ -45,39 +43,9 @@ async fn post_package_archive(
|
||||||
}
|
}
|
||||||
|
|
||||||
let clone = Arc::clone(&global.repo_manager);
|
let clone = Arc::clone(&global.repo_manager);
|
||||||
|
tokio::task::spawn_blocking(move || clone.write().unwrap().add_pkg_from_path(&repo, &path))
|
||||||
let repo_clone = repo.clone();
|
|
||||||
let pkg = tokio::task::spawn_blocking(move || {
|
|
||||||
clone.write().unwrap().add_pkg_from_path(&repo_clone, &path)
|
|
||||||
})
|
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
// Query the repo for its ID, or create it if it does not already exist
|
|
||||||
let repo_entity = db_repo::Entity::find()
|
|
||||||
.filter(db_repo::Column::Name.eq(&repo))
|
|
||||||
.one(&global.db)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let repo_id = if let Some(repo_entity) = repo_entity {
|
|
||||||
repo_entity.id
|
|
||||||
} else {
|
|
||||||
let model = db_repo::ActiveModel {
|
|
||||||
name: sea_orm::Set(repo.clone()),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
db_repo::Entity::insert(model)
|
|
||||||
.exec(&global.db)
|
|
||||||
.await?
|
|
||||||
.last_insert_id
|
|
||||||
};
|
|
||||||
|
|
||||||
// Insert the package's data into the database
|
|
||||||
let mut model: db_package::ActiveModel = pkg.into();
|
|
||||||
model.repo_id = sea_orm::Set(repo_id);
|
|
||||||
|
|
||||||
model.insert(&global.db).await?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,10 @@
|
||||||
use chrono::NaiveDateTime;
|
|
||||||
use libarchive::read::{Archive, Builder};
|
use libarchive::read::{Archive, Builder};
|
||||||
use libarchive::{Entry, ReadFilter};
|
use libarchive::{Entry, ReadFilter};
|
||||||
use sea_orm::ActiveValue::Set;
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{self, BufRead, BufReader, BufWriter, Read, Write};
|
use std::io::{self, BufRead, BufReader, BufWriter, Read, Write};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use crate::db::entities::package;
|
|
||||||
|
|
||||||
const IGNORED_FILES: [&str; 5] = [".BUILDINFO", ".INSTALL", ".MTREE", ".PKGINFO", ".CHANGELOG"];
|
const IGNORED_FILES: [&str; 5] = [".BUILDINFO", ".INSTALL", ".MTREE", ".PKGINFO", ".CHANGELOG"];
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -21,18 +17,18 @@ pub struct Package {
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct PkgInfo {
|
pub struct PkgInfo {
|
||||||
pub base: String,
|
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
pub base: 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 description: Option<String>,
|
pub build_date: i64,
|
||||||
pub size: i64,
|
pub packager: String,
|
||||||
pub csize: i64,
|
pub pgpsig: String,
|
||||||
pub url: Option<String>,
|
pub pgpsigsize: i64,
|
||||||
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>,
|
||||||
|
|
@ -42,7 +38,7 @@ pub struct PkgInfo {
|
||||||
pub optdepends: Vec<String>,
|
pub optdepends: Vec<String>,
|
||||||
pub makedepends: Vec<String>,
|
pub makedepends: Vec<String>,
|
||||||
pub checkdepends: Vec<String>,
|
pub checkdepends: Vec<String>,
|
||||||
pub sha256sum: String,
|
pub sha256sum: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
|
@ -74,27 +70,23 @@ 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 = Some(value.to_string()),
|
"pkgdesc" => self.description = value.to_string(),
|
||||||
"size" => {
|
"size" => {
|
||||||
self.size = value.parse().map_err(|_| ParsePkgInfoError::InvalidSize)?
|
self.size = value.parse().map_err(|_| ParsePkgInfoError::InvalidSize)?
|
||||||
}
|
}
|
||||||
"url" => self.url = Some(value.to_string()),
|
"url" => self.url = value.to_string(),
|
||||||
"arch" => self.arch = value.to_string(),
|
"arch" => self.arch = value.to_string(),
|
||||||
"builddate" => {
|
"builddate" => {
|
||||||
let seconds: i64 = value
|
self.build_date = 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 = Some(value.to_string()),
|
"packager" => self.packager = value.to_string(),
|
||||||
"pgpsig" => self.pgpsig = Some(value.to_string()),
|
"pgpsig" => self.pgpsig = value.to_string(),
|
||||||
"pgpsigsize" => {
|
"pgpsigsize" => {
|
||||||
self.pgpsigsize = Some(
|
self.pgpsigsize = value
|
||||||
value
|
|
||||||
.parse()
|
.parse()
|
||||||
.map_err(|_| ParsePkgInfoError::InvalidPgpSigSize)?,
|
.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()),
|
||||||
|
|
@ -164,9 +156,7 @@ impl Package {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(mut info) = info {
|
if let Some(mut info) = info {
|
||||||
// I'll take my chances on a file size fitting in an i64
|
info.csize = fs::metadata(path.as_ref())?.len();
|
||||||
info.csize = fs::metadata(path.as_ref())?.len().try_into().unwrap();
|
|
||||||
info.sha256sum = sha256::try_digest(path.as_ref())?;
|
|
||||||
|
|
||||||
Ok(Package {
|
Ok(Package {
|
||||||
path: path.as_ref().to_path_buf(),
|
path: path.as_ref().to_path_buf(),
|
||||||
|
|
@ -182,6 +172,12 @@ impl Package {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn calculate_checksum(&mut self) -> io::Result<()> {
|
||||||
|
self.info.sha256sum = Some(sha256::try_digest(self.path.as_ref())?);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn full_name(&self) -> String {
|
pub fn full_name(&self) -> String {
|
||||||
format!(
|
format!(
|
||||||
"{}-{}-{}",
|
"{}-{}-{}",
|
||||||
|
|
@ -220,27 +216,20 @@ 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())?;
|
||||||
|
|
||||||
write("SHA256SUM", &info.sha256sum)?;
|
if let Some(checksum) = &info.sha256sum {
|
||||||
|
write("SHA256SUM", checksum)?;
|
||||||
if let Some(ref url) = info.url {
|
|
||||||
write("URL", url)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
write("URL", &info.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.timestamp().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"))?;
|
||||||
|
|
@ -267,26 +256,3 @@ impl Package {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Package> for package::ActiveModel {
|
|
||||||
fn from(pkg: Package) -> Self {
|
|
||||||
let info = pkg.info;
|
|
||||||
|
|
||||||
package::ActiveModel {
|
|
||||||
base: Set(info.base),
|
|
||||||
name: Set(info.name),
|
|
||||||
version: Set(info.version),
|
|
||||||
arch: Set(info.arch),
|
|
||||||
size: Set(info.size),
|
|
||||||
c_size: Set(info.csize),
|
|
||||||
description: Set(info.description),
|
|
||||||
url: Set(info.url),
|
|
||||||
build_date: Set(info.build_date),
|
|
||||||
packager: Set(info.packager),
|
|
||||||
pgp_sig: Set(info.pgpsig),
|
|
||||||
pgp_sig_size: Set(info.pgpsigsize),
|
|
||||||
sha256_sum: Set(info.sha256sum),
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue