Compare commits
No commits in common. "86cd52a0813d034d3d5ab5fbc36e72a75d7fc4c0" and "af27b06df1d0b047b9504cca32b33f67dfbd3126" have entirely different histories.
86cd52a081
...
af27b06df1
|
|
@ -2,5 +2,3 @@ target/
|
||||||
.git/
|
.git/
|
||||||
server/data/
|
server/data/
|
||||||
server/test.db/
|
server/test.db/
|
||||||
Dockerfile
|
|
||||||
docker-compose.yml
|
|
||||||
|
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
branches: [dev]
|
|
||||||
platform: 'linux/amd64'
|
|
||||||
depends_on:
|
|
||||||
- build
|
|
||||||
|
|
||||||
pipeline:
|
|
||||||
dev:
|
|
||||||
image: 'woodpeckerci/plugin-docker-buildx'
|
|
||||||
secrets:
|
|
||||||
- 'docker_username'
|
|
||||||
- 'docker_password'
|
|
||||||
settings:
|
|
||||||
registry: 'git.rustybever.be'
|
|
||||||
repo: 'git.rustybever.be/chewing_bever/rieter'
|
|
||||||
tags:
|
|
||||||
- 'dev'
|
|
||||||
platforms: [ 'linux/amd64' ]
|
|
||||||
when:
|
|
||||||
event: push
|
|
||||||
branch: dev
|
|
||||||
|
|
@ -16,6 +16,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
requests
|
requests
|
||||||
* Packages of architecture "any" are part of every architecture's
|
* Packages of architecture "any" are part of every architecture's
|
||||||
database
|
database
|
||||||
* Bearer authentication for private routes
|
|
||||||
* REST API
|
|
||||||
* Repository & package information available using JSON REST API
|
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -4,9 +4,3 @@ members = [
|
||||||
'libarchive',
|
'libarchive',
|
||||||
'libarchive3-sys'
|
'libarchive3-sys'
|
||||||
]
|
]
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
lto = "fat"
|
|
||||||
codegen-units = 1
|
|
||||||
panic = "abort"
|
|
||||||
strip = true
|
|
||||||
|
|
|
||||||
33
Dockerfile
33
Dockerfile
|
|
@ -4,6 +4,21 @@ ARG DI_VER=1.2.5
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
# RUN apk add --no-cache \
|
||||||
|
# build-base \
|
||||||
|
# curl \
|
||||||
|
# make \
|
||||||
|
# unzip \
|
||||||
|
# pkgconf \
|
||||||
|
# openssl openssl-libs-static openssl-dev \
|
||||||
|
# libarchive-static libarchive-dev \
|
||||||
|
# zlib-static zlib-dev \
|
||||||
|
# bzip2-static bzip2-dev \
|
||||||
|
# xz-static xz-dev \
|
||||||
|
# expat-static expat-dev \
|
||||||
|
# zstd-static zstd-dev \
|
||||||
|
# lz4-static lz4-dev \
|
||||||
|
# acl-static acl-dev
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
build-base \
|
build-base \
|
||||||
curl \
|
curl \
|
||||||
|
|
@ -27,29 +42,23 @@ COPY . .
|
||||||
# LIBARCHIVE_LDFLAGS='-lssl -lcrypto -L/lib -lz -lbz2 -llzma -lexpat -lzstd -llz4'
|
# LIBARCHIVE_LDFLAGS='-lssl -lcrypto -L/lib -lz -lbz2 -llzma -lexpat -lzstd -llz4'
|
||||||
# LIBARCHIVE_LDFLAGS='-L/usr/lib -lz -lbz2 -llzma -lexpat -lzstd -llz4 -lsqlite3'
|
# LIBARCHIVE_LDFLAGS='-L/usr/lib -lz -lbz2 -llzma -lexpat -lzstd -llz4 -lsqlite3'
|
||||||
|
|
||||||
# https://users.rust-lang.org/t/sigsegv-with-program-linked-against-openssl-in-an-alpine-container/52172
|
|
||||||
ENV RUSTFLAGS='-C target-feature=-crt-static'
|
|
||||||
|
|
||||||
RUN cargo build --release && \
|
RUN cargo build --release && \
|
||||||
du -h target/release/rieterd && \
|
du -h target/release/rieterd && \
|
||||||
readelf -d target/release/rieterd && \
|
readelf -d target/release/rieterd && \
|
||||||
chmod +x target/release/rieterd
|
chmod +x target/release/rieterd
|
||||||
|
# [ "$(readelf -d target/debug/rieterd | grep NEEDED | wc -l)" = 0 ] && \
|
||||||
|
# chmod +x target/debug/rieterd
|
||||||
|
|
||||||
|
|
||||||
FROM alpine:3.18
|
FROM alpine:3.18
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
libgcc \
|
libarchive
|
||||||
libarchive \
|
|
||||||
openssl
|
|
||||||
|
|
||||||
COPY --from=builder /app/dumb-init /bin/dumb-init
|
COPY --from=builder /app/dumb-init /bin/dumb-init
|
||||||
COPY --from=builder /app/target/release/rieterd /bin/rieterd
|
COPY --from=builder /app/target/debug/rieterd /bin/rieterd
|
||||||
|
|
||||||
ENV RIETER_PKG_DIR=/data/pkgs \
|
|
||||||
RIETER_DATA_DIR=/data
|
|
||||||
|
|
||||||
WORKDIR /data
|
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/dumb-init", "--"]
|
ENTRYPOINT ["/bin/dumb-init", "--"]
|
||||||
CMD ["/bin/rieterd"]
|
CMD ["/bin/rieterd"]
|
||||||
|
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
version: '3.4'
|
|
||||||
|
|
||||||
services:
|
|
||||||
app:
|
|
||||||
image: 'rieterd:latest'
|
|
||||||
ports:
|
|
||||||
- '8000:8000'
|
|
||||||
environment:
|
|
||||||
- 'RIETER_API_KEY=test'
|
|
||||||
- 'RIETER_DATABASE_URL=postgres://rieter:rieter@db:5432/rieter'
|
|
||||||
|
|
||||||
db:
|
|
||||||
image: 'postgres:15.3-alpine'
|
|
||||||
environment:
|
|
||||||
- 'POSTGRES_DB=rieter'
|
|
||||||
- 'POSTGRES_USER=rieter'
|
|
||||||
- 'POSTGRES_PASSWORD=rieter'
|
|
||||||
|
|
@ -39,7 +39,7 @@ pub enum ReadFormat {
|
||||||
Zip,
|
Zip,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum ReadFilter {
|
pub enum ReadFilter {
|
||||||
All,
|
All,
|
||||||
Bzip2,
|
Bzip2,
|
||||||
|
|
@ -314,12 +314,6 @@ pub trait Entry {
|
||||||
ffi::archive_entry_set_mode(self.entry_mut(), mode);
|
ffi::archive_entry_set_mode(self.entry_mut(), mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_size(&mut self, size: i64) {
|
|
||||||
unsafe {
|
|
||||||
ffi::archive_entry_set_size(self.entry_mut(), size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
|
|
||||||
|
|
@ -39,32 +39,22 @@ impl FileWriter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut buf = [0; 4096];
|
let mut buf = [0; 8192];
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match r.read(&mut buf) {
|
match r.read(&mut buf) {
|
||||||
Ok(0) => return Ok(()),
|
Ok(0) => return Ok(()),
|
||||||
// Write entire buffer
|
Ok(written) => unsafe {
|
||||||
Ok(buf_len) => {
|
match ffi::archive_write_data(
|
||||||
let mut written: usize = 0;
|
self.handle_mut(),
|
||||||
|
buf.as_ptr() as *const _,
|
||||||
while written < buf_len {
|
written,
|
||||||
let res = unsafe {
|
) as i32
|
||||||
ffi::archive_write_data(
|
{
|
||||||
self.handle_mut(),
|
ffi::ARCHIVE_OK => (),
|
||||||
&buf[written] as *const u8 as *const _,
|
_ => return Err(ArchiveError::from(self as &dyn Handle).into()),
|
||||||
buf_len - written,
|
};
|
||||||
)
|
},
|
||||||
} as isize;
|
|
||||||
|
|
||||||
// Negative values signal errors
|
|
||||||
if res < 0 {
|
|
||||||
return Err(ArchiveError::from(self as &dyn Handle).into());
|
|
||||||
}
|
|
||||||
|
|
||||||
written += usize::try_from(res).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => match err.kind() {
|
Err(err) => match err.kind() {
|
||||||
io::ErrorKind::Interrupted => (),
|
io::ErrorKind::Interrupted => (),
|
||||||
_ => return Err(err.into()),
|
_ => return Err(err.into()),
|
||||||
|
|
|
||||||
|
|
@ -8,27 +8,20 @@ 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-migration = "0.12.1"
|
|
||||||
serde = { version = "1.0.178", features = ["derive"] }
|
|
||||||
sha256 = "1.1.4"
|
sha256 = "1.1.4"
|
||||||
tokio = { version = "1.29.1", features = ["full"] }
|
tokio = { version = "1.29.1", features = ["full"] }
|
||||||
tokio-util = { version = "0.7.8", features = ["io"] }
|
tokio-util = { version = "0.7.8", features = ["io"] }
|
||||||
tower = { version = "0.4.13", features = ["make"] }
|
tower = { version = "0.4.13", features = ["make"] }
|
||||||
tower-http = { version = "0.4.1", features = ["fs", "trace", "auth"] }
|
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]
|
[profile.release]
|
||||||
version = "0.12.1"
|
lto = "fat"
|
||||||
features = [
|
codegen-units = 1
|
||||||
"sqlx-sqlite",
|
panic = "abort"
|
||||||
"sqlx-postgres",
|
strip = true
|
||||||
"runtime-tokio-rustls",
|
|
||||||
"macros",
|
|
||||||
"with-chrono"
|
|
||||||
]
|
|
||||||
|
|
|
||||||
|
|
@ -1,73 +0,0 @@
|
||||||
mod pagination;
|
|
||||||
|
|
||||||
use axum::extract::{Path, Query, State};
|
|
||||||
use axum::routing::get;
|
|
||||||
use axum::Json;
|
|
||||||
use axum::Router;
|
|
||||||
|
|
||||||
use pagination::PaginatedResponse;
|
|
||||||
|
|
||||||
use crate::db;
|
|
||||||
|
|
||||||
pub fn router() -> Router<crate::Global> {
|
|
||||||
Router::new()
|
|
||||||
.route("/repos", get(get_repos))
|
|
||||||
.route("/repos/:id", get(get_single_repo))
|
|
||||||
.route("/packages", get(get_packages))
|
|
||||||
.route("/packages/:id", get(get_single_package))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_repos(
|
|
||||||
State(global): State<crate::Global>,
|
|
||||||
Query(pagination): Query<pagination::Query>,
|
|
||||||
) -> crate::Result<Json<PaginatedResponse<db::repo::Model>>> {
|
|
||||||
let (total_pages, repos) = global
|
|
||||||
.db
|
|
||||||
.repos(
|
|
||||||
pagination.per_page.unwrap_or(25),
|
|
||||||
pagination.page.unwrap_or(1) - 1,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
Ok(Json(pagination.res(total_pages, repos)))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_single_repo(
|
|
||||||
State(global): State<crate::Global>,
|
|
||||||
Path(id): Path<i32>,
|
|
||||||
) -> crate::Result<Json<db::repo::Model>> {
|
|
||||||
let repo = global
|
|
||||||
.db
|
|
||||||
.repo(id)
|
|
||||||
.await?
|
|
||||||
.ok_or(axum::http::StatusCode::NOT_FOUND)?;
|
|
||||||
|
|
||||||
Ok(Json(repo))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_packages(
|
|
||||||
State(global): State<crate::Global>,
|
|
||||||
Query(pagination): Query<pagination::Query>,
|
|
||||||
) -> crate::Result<Json<PaginatedResponse<db::package::Model>>> {
|
|
||||||
let (total_pages, pkgs) = global
|
|
||||||
.db
|
|
||||||
.packages(
|
|
||||||
pagination.per_page.unwrap_or(25),
|
|
||||||
pagination.page.unwrap_or(1) - 1,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(Json(pagination.res(total_pages, pkgs)))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_single_package(
|
|
||||||
State(global): State<crate::Global>,
|
|
||||||
Path(id): Path<i32>,
|
|
||||||
) -> crate::Result<Json<crate::db::FullPackage>> {
|
|
||||||
let entry = global
|
|
||||||
.db
|
|
||||||
.full_package(id)
|
|
||||||
.await?
|
|
||||||
.ok_or(axum::http::StatusCode::NOT_FOUND)?;
|
|
||||||
|
|
||||||
Ok(Json(entry))
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
pub const DEFAULT_PAGE: u64 = 0;
|
|
||||||
pub const DEFAULT_PER_PAGE: u64 = 25;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
pub struct Query {
|
|
||||||
pub page: Option<u64>,
|
|
||||||
pub per_page: Option<u64>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
|
||||||
pub struct PaginatedResponse<T>
|
|
||||||
where
|
|
||||||
T: for<'de> Serialize,
|
|
||||||
{
|
|
||||||
pub page: u64,
|
|
||||||
pub per_page: u64,
|
|
||||||
pub total_pages: u64,
|
|
||||||
pub count: usize,
|
|
||||||
pub items: Vec<T>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Query {
|
|
||||||
pub fn res<T: for<'de> Serialize>(
|
|
||||||
self,
|
|
||||||
total_pages: u64,
|
|
||||||
items: Vec<T>,
|
|
||||||
) -> PaginatedResponse<T> {
|
|
||||||
PaginatedResponse {
|
|
||||||
page: self.page.unwrap_or(DEFAULT_PAGE),
|
|
||||||
per_page: self.per_page.unwrap_or(DEFAULT_PER_PAGE),
|
|
||||||
total_pages,
|
|
||||||
count: items.len(),
|
|
||||||
items,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -4,47 +4,28 @@ use crate::{Config, Global};
|
||||||
use axum::extract::FromRef;
|
use axum::extract::FromRef;
|
||||||
use axum::Router;
|
use axum::Router;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use std::io;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use tower_http::trace::TraceLayer;
|
use tower_http::trace::TraceLayer;
|
||||||
use tracing::debug;
|
|
||||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(author, version, about, long_about = None)]
|
#[command(author, version, about, long_about = None)]
|
||||||
pub struct Cli {
|
pub struct Cli {
|
||||||
/// Directory where package archives will be stored
|
|
||||||
#[arg(env = "RIETER_PKG_DIR")]
|
|
||||||
pub pkg_dir: PathBuf,
|
|
||||||
/// Directory where repository metadata & SQLite database is stored
|
|
||||||
#[arg(env = "RIETER_DATA_DIR")]
|
|
||||||
pub data_dir: PathBuf,
|
|
||||||
/// API key to authenticate private routes with
|
|
||||||
#[arg(env = "RIETER_API_KEY")]
|
|
||||||
pub api_key: String,
|
|
||||||
|
|
||||||
/// Database connection URL; either sqlite:// or postgres://. Defaults to rieter.sqlite in the
|
|
||||||
/// data directory
|
|
||||||
#[arg(short, long, env = "RIETER_DATABASE_URL")]
|
|
||||||
pub database_url: Option<String>,
|
|
||||||
/// Port the server will listen on
|
/// Port the server will listen on
|
||||||
#[arg(
|
#[arg(short, long, value_name = "PORT", default_value_t = 8000)]
|
||||||
short,
|
|
||||||
long,
|
|
||||||
value_name = "PORT",
|
|
||||||
default_value_t = 8000,
|
|
||||||
env = "RIETER_PORT"
|
|
||||||
)]
|
|
||||||
pub port: u16,
|
pub port: u16,
|
||||||
/// Log levels for the tracing
|
/// Log levels for the tracing
|
||||||
#[arg(
|
#[arg(
|
||||||
long,
|
long,
|
||||||
value_name = "LOG_LEVEL",
|
value_name = "LOG_LEVEL",
|
||||||
default_value = "tower_http=debug,rieterd=debug",
|
default_value = "tower_http=debug,rieterd=debug"
|
||||||
env = "RIETER_LOG"
|
|
||||||
)]
|
)]
|
||||||
pub log: String,
|
pub log: String,
|
||||||
|
/// Directory where package archives will be stored
|
||||||
|
pub pkg_dir: PathBuf,
|
||||||
|
/// Directory where repository metadata is stored
|
||||||
|
pub repo_dir: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromRef<Global> for Arc<RwLock<RepoGroupManager>> {
|
impl FromRef<Global> for Arc<RwLock<RepoGroupManager>> {
|
||||||
|
|
@ -61,52 +42,30 @@ impl Cli {
|
||||||
.init();
|
.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run(&self) -> crate::Result<()> {
|
pub async fn run(&self) {
|
||||||
self.init_tracing();
|
self.init_tracing();
|
||||||
|
|
||||||
let db_url = if let Some(url) = &self.database_url {
|
|
||||||
url.clone()
|
|
||||||
} else {
|
|
||||||
format!(
|
|
||||||
"sqlite://{}",
|
|
||||||
self.data_dir.join("rieter.sqlite").to_string_lossy()
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
debug!("Connecting to database with URL {}", db_url);
|
|
||||||
|
|
||||||
let db = crate::db::RieterDb::connect(db_url).await?;
|
|
||||||
// let db = crate::db::init("postgres://rieter:rieter@localhost:5432/rieter")
|
|
||||||
// .await
|
|
||||||
// .unwrap();
|
|
||||||
|
|
||||||
let config = Config {
|
let config = Config {
|
||||||
data_dir: self.data_dir.clone(),
|
repo_dir: self.repo_dir.clone(),
|
||||||
repo_dir: self.data_dir.join("repos"),
|
|
||||||
pkg_dir: self.pkg_dir.clone(),
|
pkg_dir: self.pkg_dir.clone(),
|
||||||
api_key: self.api_key.clone(),
|
|
||||||
};
|
};
|
||||||
let repo_manager = RepoGroupManager::new(&config.repo_dir, &self.pkg_dir);
|
let repo_manager = RepoGroupManager::new(&self.repo_dir, &self.pkg_dir);
|
||||||
|
|
||||||
let global = Global {
|
let global = Global {
|
||||||
config,
|
config,
|
||||||
repo_manager: Arc::new(RwLock::new(repo_manager)),
|
repo_manager: Arc::new(RwLock::new(repo_manager)),
|
||||||
db,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// build our application with a single route
|
// build our application with a single route
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.nest("/api", crate::api::router())
|
.merge(crate::repo::router())
|
||||||
.merge(crate::repo::router(&self.api_key))
|
|
||||||
.with_state(global)
|
.with_state(global)
|
||||||
.layer(TraceLayer::new_for_http());
|
.layer(TraceLayer::new_for_http());
|
||||||
|
|
||||||
// run it with hyper on localhost:3000
|
// run it with hyper on localhost:3000
|
||||||
Ok(
|
axum::Server::bind(&format!("0.0.0.0:{}", self.port).parse().unwrap())
|
||||||
axum::Server::bind(&format!("0.0.0.0:{}", self.port).parse().unwrap())
|
.serve(app.into_make_service())
|
||||||
.serve(app.into_make_service())
|
.await
|
||||||
.await
|
.unwrap();
|
||||||
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
use super::RieterDb;
|
|
||||||
use sea_orm::{DbBackend, DbErr, ExecResult, QueryResult, Statement};
|
|
||||||
use std::{future::Future, pin::Pin};
|
|
||||||
|
|
||||||
// Allows RieterDb objects to be passed to ORM functions
|
|
||||||
impl sea_orm::ConnectionTrait for RieterDb {
|
|
||||||
fn get_database_backend(&self) -> DbBackend {
|
|
||||||
self.conn.get_database_backend()
|
|
||||||
}
|
|
||||||
fn execute<'life0, 'async_trait>(
|
|
||||||
&'life0 self,
|
|
||||||
stmt: Statement,
|
|
||||||
) -> Pin<Box<dyn Future<Output = std::result::Result<ExecResult, DbErr>> + Send + 'async_trait>>
|
|
||||||
where
|
|
||||||
Self: 'async_trait,
|
|
||||||
'life0: 'async_trait,
|
|
||||||
{
|
|
||||||
self.conn.execute(stmt)
|
|
||||||
}
|
|
||||||
fn execute_unprepared<'life0, 'life1, 'async_trait>(
|
|
||||||
&'life0 self,
|
|
||||||
sql: &'life1 str,
|
|
||||||
) -> Pin<Box<dyn Future<Output = std::result::Result<ExecResult, DbErr>> + Send + 'async_trait>>
|
|
||||||
where
|
|
||||||
Self: 'async_trait,
|
|
||||||
'life0: 'async_trait,
|
|
||||||
'life1: 'async_trait,
|
|
||||||
{
|
|
||||||
self.conn.execute_unprepared(sql)
|
|
||||||
}
|
|
||||||
fn query_one<'life0, 'async_trait>(
|
|
||||||
&'life0 self,
|
|
||||||
stmt: Statement,
|
|
||||||
) -> Pin<
|
|
||||||
Box<
|
|
||||||
dyn Future<Output = std::result::Result<Option<QueryResult>, DbErr>>
|
|
||||||
+ Send
|
|
||||||
+ 'async_trait,
|
|
||||||
>,
|
|
||||||
>
|
|
||||||
where
|
|
||||||
Self: 'async_trait,
|
|
||||||
'life0: 'async_trait,
|
|
||||||
{
|
|
||||||
self.conn.query_one(stmt)
|
|
||||||
}
|
|
||||||
fn query_all<'life0, 'async_trait>(
|
|
||||||
&'life0 self,
|
|
||||||
stmt: Statement,
|
|
||||||
) -> Pin<
|
|
||||||
Box<
|
|
||||||
dyn Future<Output = std::result::Result<Vec<QueryResult>, DbErr>> + Send + 'async_trait,
|
|
||||||
>,
|
|
||||||
>
|
|
||||||
where
|
|
||||||
Self: 'async_trait,
|
|
||||||
'life0: 'async_trait,
|
|
||||||
{
|
|
||||||
self.conn.query_all(stmt)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
|
|
||||||
|
|
||||||
pub mod prelude;
|
|
||||||
|
|
||||||
pub mod package;
|
|
||||||
pub mod package_conflicts;
|
|
||||||
pub mod package_depends;
|
|
||||||
pub mod package_file;
|
|
||||||
pub mod package_group;
|
|
||||||
pub mod package_license;
|
|
||||||
pub mod package_provides;
|
|
||||||
pub mod package_replaces;
|
|
||||||
pub mod repo;
|
|
||||||
|
|
@ -1,101 +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_conflicts::Entity")]
|
|
||||||
PackageConflicts,
|
|
||||||
#[sea_orm(has_many = "super::package_depends::Entity")]
|
|
||||||
PackageDepends,
|
|
||||||
#[sea_orm(has_many = "super::package_file::Entity")]
|
|
||||||
PackageFile,
|
|
||||||
#[sea_orm(has_many = "super::package_group::Entity")]
|
|
||||||
PackageGroup,
|
|
||||||
#[sea_orm(has_many = "super::package_license::Entity")]
|
|
||||||
PackageLicense,
|
|
||||||
#[sea_orm(has_many = "super::package_provides::Entity")]
|
|
||||||
PackageProvides,
|
|
||||||
#[sea_orm(has_many = "super::package_replaces::Entity")]
|
|
||||||
PackageReplaces,
|
|
||||||
#[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_conflicts::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::PackageConflicts.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::package_depends::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::PackageDepends.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::package_file::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::PackageFile.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::package_group::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::PackageGroup.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::package_license::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::PackageLicense.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::package_provides::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::PackageProvides.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::package_replaces::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::PackageReplaces.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_conflicts")]
|
|
||||||
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,35 +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_depends")]
|
|
||||||
pub struct Model {
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub package_id: i32,
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub r#type: crate::db::PackageDepend,
|
|
||||||
#[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,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_file")]
|
|
||||||
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,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_group")]
|
|
||||||
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,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,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_provides")]
|
|
||||||
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,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_replaces")]
|
|
||||||
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,11 +0,0 @@
|
||||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
|
|
||||||
|
|
||||||
pub use super::package::Entity as Package;
|
|
||||||
pub use super::package_conflicts::Entity as PackageConflicts;
|
|
||||||
pub use super::package_depends::Entity as PackageDepends;
|
|
||||||
pub use super::package_file::Entity as PackageFile;
|
|
||||||
pub use super::package_group::Entity as PackageGroup;
|
|
||||||
pub use super::package_license::Entity as PackageLicense;
|
|
||||||
pub use super::package_provides::Entity as PackageProvides;
|
|
||||||
pub use super::package_replaces::Entity as PackageReplaces;
|
|
||||||
pub use super::repo::Entity as Repo;
|
|
||||||
|
|
@ -1,28 +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 = "repo")]
|
|
||||||
pub struct Model {
|
|
||||||
#[sea_orm(primary_key)]
|
|
||||||
pub id: i32,
|
|
||||||
#[sea_orm(unique)]
|
|
||||||
pub name: String,
|
|
||||||
pub description: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
||||||
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 {}
|
|
||||||
|
|
@ -1,378 +0,0 @@
|
||||||
use sea_orm_migration::prelude::*;
|
|
||||||
|
|
||||||
pub struct Migration;
|
|
||||||
|
|
||||||
impl MigrationName for Migration {
|
|
||||||
fn name(&self) -> &str {
|
|
||||||
"m_20230730_000001_create_repo_tables"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl MigrationTrait for Migration {
|
|
||||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(Repo::Table)
|
|
||||||
.col(
|
|
||||||
ColumnDef::new(Repo::Id)
|
|
||||||
.integer()
|
|
||||||
.not_null()
|
|
||||||
.auto_increment()
|
|
||||||
.primary_key(),
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(Repo::Name).string().not_null().unique_key())
|
|
||||||
.col(ColumnDef::new(Repo::Description).string())
|
|
||||||
.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?;
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(PackageGroup::Table)
|
|
||||||
.col(ColumnDef::new(PackageGroup::PackageId).integer().not_null())
|
|
||||||
.col(
|
|
||||||
ColumnDef::new(PackageGroup::Value)
|
|
||||||
.string_len(255)
|
|
||||||
.not_null(),
|
|
||||||
)
|
|
||||||
.primary_key(
|
|
||||||
Index::create()
|
|
||||||
.col(PackageGroup::PackageId)
|
|
||||||
.col(PackageGroup::Value),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKey::create()
|
|
||||||
.name("fk-package_group-package_id")
|
|
||||||
.from(PackageGroup::Table, PackageGroup::PackageId)
|
|
||||||
.to(Package::Table, Package::Id)
|
|
||||||
.on_delete(ForeignKeyAction::Cascade),
|
|
||||||
)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(PackageReplaces::Table)
|
|
||||||
.col(
|
|
||||||
ColumnDef::new(PackageReplaces::PackageId)
|
|
||||||
.integer()
|
|
||||||
.not_null(),
|
|
||||||
)
|
|
||||||
.col(
|
|
||||||
ColumnDef::new(PackageReplaces::Value)
|
|
||||||
.string_len(255)
|
|
||||||
.not_null(),
|
|
||||||
)
|
|
||||||
.primary_key(
|
|
||||||
Index::create()
|
|
||||||
.col(PackageReplaces::PackageId)
|
|
||||||
.col(PackageReplaces::Value),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKey::create()
|
|
||||||
.name("fk-package_replaces-package_id")
|
|
||||||
.from(PackageReplaces::Table, PackageReplaces::PackageId)
|
|
||||||
.to(Package::Table, Package::Id)
|
|
||||||
.on_delete(ForeignKeyAction::Cascade),
|
|
||||||
)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(PackageConflicts::Table)
|
|
||||||
.col(
|
|
||||||
ColumnDef::new(PackageConflicts::PackageId)
|
|
||||||
.integer()
|
|
||||||
.not_null(),
|
|
||||||
)
|
|
||||||
.col(
|
|
||||||
ColumnDef::new(PackageConflicts::Value)
|
|
||||||
.string_len(255)
|
|
||||||
.not_null(),
|
|
||||||
)
|
|
||||||
.primary_key(
|
|
||||||
Index::create()
|
|
||||||
.col(PackageConflicts::PackageId)
|
|
||||||
.col(PackageConflicts::Value),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKey::create()
|
|
||||||
.name("fk-package_conflicts-package_id")
|
|
||||||
.from(PackageConflicts::Table, PackageConflicts::PackageId)
|
|
||||||
.to(Package::Table, Package::Id)
|
|
||||||
.on_delete(ForeignKeyAction::Cascade),
|
|
||||||
)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(PackageProvides::Table)
|
|
||||||
.col(
|
|
||||||
ColumnDef::new(PackageProvides::PackageId)
|
|
||||||
.integer()
|
|
||||||
.not_null(),
|
|
||||||
)
|
|
||||||
.col(
|
|
||||||
ColumnDef::new(PackageProvides::Value)
|
|
||||||
.string_len(255)
|
|
||||||
.not_null(),
|
|
||||||
)
|
|
||||||
.primary_key(
|
|
||||||
Index::create()
|
|
||||||
.col(PackageProvides::PackageId)
|
|
||||||
.col(PackageProvides::Value),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKey::create()
|
|
||||||
.name("fk-package_provides-package_id")
|
|
||||||
.from(PackageProvides::Table, PackageProvides::PackageId)
|
|
||||||
.to(Package::Table, Package::Id)
|
|
||||||
.on_delete(ForeignKeyAction::Cascade),
|
|
||||||
)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(PackageDepends::Table)
|
|
||||||
.col(
|
|
||||||
ColumnDef::new(PackageDepends::PackageId)
|
|
||||||
.integer()
|
|
||||||
.not_null(),
|
|
||||||
)
|
|
||||||
.col(
|
|
||||||
ColumnDef::new(PackageDepends::Type)
|
|
||||||
.string_len(6)
|
|
||||||
.not_null(),
|
|
||||||
)
|
|
||||||
.col(
|
|
||||||
ColumnDef::new(PackageDepends::Value)
|
|
||||||
.string_len(255)
|
|
||||||
.not_null(),
|
|
||||||
)
|
|
||||||
.primary_key(
|
|
||||||
Index::create()
|
|
||||||
.col(PackageDepends::PackageId)
|
|
||||||
.col(PackageDepends::Type)
|
|
||||||
.col(PackageDepends::Value),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKey::create()
|
|
||||||
.name("fk-package_depends-package_id")
|
|
||||||
.from(PackageDepends::Table, PackageDepends::PackageId)
|
|
||||||
.to(Package::Table, Package::Id)
|
|
||||||
.on_delete(ForeignKeyAction::Cascade),
|
|
||||||
)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(PackageFile::Table)
|
|
||||||
.col(ColumnDef::new(PackageFile::PackageId).integer().not_null())
|
|
||||||
.col(
|
|
||||||
ColumnDef::new(PackageFile::Value)
|
|
||||||
.string_len(255)
|
|
||||||
.not_null(),
|
|
||||||
)
|
|
||||||
.primary_key(
|
|
||||||
Index::create()
|
|
||||||
.col(PackageFile::PackageId)
|
|
||||||
.col(PackageFile::Value),
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKey::create()
|
|
||||||
.name("fk-package_file-package_id")
|
|
||||||
.from(PackageFile::Table, PackageFile::PackageId)
|
|
||||||
.to(Package::Table, Package::Id)
|
|
||||||
.on_delete(ForeignKeyAction::Cascade),
|
|
||||||
)
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define how to rollback this migration: Drop the Bakery table.
|
|
||||||
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(PackageGroup::Table).to_owned())
|
|
||||||
.await?;
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(PackageReplaces::Table).to_owned())
|
|
||||||
.await?;
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(PackageConflicts::Table).to_owned())
|
|
||||||
.await?;
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(PackageProvides::Table).to_owned())
|
|
||||||
.await?;
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(PackageDepends::Table).to_owned())
|
|
||||||
.await?;
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(PackageFile::Table).to_owned())
|
|
||||||
.await?;
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(Package::Table).to_owned())
|
|
||||||
.await?;
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(Repo::Table).to_owned())
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum Repo {
|
|
||||||
Table,
|
|
||||||
Id,
|
|
||||||
Name,
|
|
||||||
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,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum PackageGroup {
|
|
||||||
Table,
|
|
||||||
PackageId,
|
|
||||||
Value,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum PackageReplaces {
|
|
||||||
Table,
|
|
||||||
PackageId,
|
|
||||||
Value,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum PackageConflicts {
|
|
||||||
Table,
|
|
||||||
PackageId,
|
|
||||||
Value,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum PackageProvides {
|
|
||||||
Table,
|
|
||||||
PackageId,
|
|
||||||
Value,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum PackageDepends {
|
|
||||||
Table,
|
|
||||||
PackageId,
|
|
||||||
Type,
|
|
||||||
Value,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum PackageFile {
|
|
||||||
Table,
|
|
||||||
PackageId,
|
|
||||||
Value,
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
use sea_orm_migration::prelude::*;
|
|
||||||
|
|
||||||
pub struct Migrator;
|
|
||||||
|
|
||||||
mod m20230730_000001_create_repo_tables;
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl MigratorTrait for Migrator {
|
|
||||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
|
||||||
vec![Box::new(m20230730_000001_create_repo_tables::Migration)]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,294 +0,0 @@
|
||||||
mod conn;
|
|
||||||
pub mod entities;
|
|
||||||
mod migrator;
|
|
||||||
|
|
||||||
use sea_orm::{
|
|
||||||
ActiveModelTrait, ColumnTrait, ConnectOptions, Database, DatabaseConnection, DeleteResult,
|
|
||||||
DeriveActiveEnum, EntityTrait, EnumIter, InsertResult, ModelTrait, NotSet, PaginatorTrait,
|
|
||||||
QueryFilter, QueryOrder, Set,
|
|
||||||
};
|
|
||||||
use sea_orm_migration::MigratorTrait;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
pub use entities::{prelude::*, *};
|
|
||||||
use migrator::Migrator;
|
|
||||||
|
|
||||||
type Result<T> = std::result::Result<T, sea_orm::DbErr>;
|
|
||||||
|
|
||||||
#[derive(EnumIter, DeriveActiveEnum, Serialize, Deserialize, PartialEq, Eq, Clone, Debug)]
|
|
||||||
#[sea_orm(rs_type = "String", db_type = "String(Some(6))")]
|
|
||||||
pub enum PackageDepend {
|
|
||||||
#[sea_orm(string_value = "depend")]
|
|
||||||
Depend,
|
|
||||||
#[sea_orm(string_value = "make")]
|
|
||||||
Make,
|
|
||||||
#[sea_orm(string_value = "check")]
|
|
||||||
Check,
|
|
||||||
#[sea_orm(string_value = "opt")]
|
|
||||||
Opt,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
|
||||||
pub struct FullPackage {
|
|
||||||
#[serde(flatten)]
|
|
||||||
entry: package::Model,
|
|
||||||
licenses: Vec<String>,
|
|
||||||
groups: Vec<String>,
|
|
||||||
replaces: Vec<String>,
|
|
||||||
provides: Vec<String>,
|
|
||||||
depends: Vec<(PackageDepend, String)>,
|
|
||||||
files: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct RieterDb {
|
|
||||||
pub conn: DatabaseConnection,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RieterDb {
|
|
||||||
pub async fn connect<C: Into<ConnectOptions>>(opt: C) -> Result<Self> {
|
|
||||||
let db = Database::connect(opt).await?;
|
|
||||||
|
|
||||||
Migrator::up(&db, None).await?;
|
|
||||||
|
|
||||||
Ok(Self { conn: db })
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn repos(&self, per_page: u64, page: u64) -> Result<(u64, Vec<repo::Model>)> {
|
|
||||||
let paginator = Repo::find()
|
|
||||||
.order_by_asc(repo::Column::Id)
|
|
||||||
.paginate(&self.conn, per_page);
|
|
||||||
let repos = paginator.fetch_page(page).await?;
|
|
||||||
let total_pages = paginator.num_pages().await?;
|
|
||||||
|
|
||||||
Ok((total_pages, repos))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn repo(&self, id: i32) -> Result<Option<repo::Model>> {
|
|
||||||
repo::Entity::find_by_id(id).one(&self.conn).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn repo_by_name(&self, name: &str) -> Result<Option<repo::Model>> {
|
|
||||||
Repo::find()
|
|
||||||
.filter(repo::Column::Name.eq(name))
|
|
||||||
.one(&self.conn)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn insert_repo(
|
|
||||||
&self,
|
|
||||||
name: &str,
|
|
||||||
description: Option<&str>,
|
|
||||||
) -> Result<InsertResult<repo::ActiveModel>> {
|
|
||||||
let model = repo::ActiveModel {
|
|
||||||
id: NotSet,
|
|
||||||
name: Set(String::from(name)),
|
|
||||||
description: Set(description.map(String::from)),
|
|
||||||
};
|
|
||||||
|
|
||||||
Repo::insert(model).exec(&self.conn).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn packages(&self, per_page: u64, page: u64) -> Result<(u64, Vec<package::Model>)> {
|
|
||||||
let paginator = Package::find()
|
|
||||||
.order_by_asc(package::Column::Id)
|
|
||||||
.paginate(&self.conn, per_page);
|
|
||||||
let packages = paginator.fetch_page(page).await?;
|
|
||||||
let total_pages = paginator.num_pages().await?;
|
|
||||||
|
|
||||||
Ok((total_pages, packages))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn package(&self, id: i32) -> Result<Option<package::Model>> {
|
|
||||||
package::Entity::find_by_id(id).one(&self.conn).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn package_by_fields(
|
|
||||||
&self,
|
|
||||||
repo_id: i32,
|
|
||||||
name: &str,
|
|
||||||
version: Option<&str>,
|
|
||||||
arch: &str,
|
|
||||||
) -> Result<Option<package::Model>> {
|
|
||||||
let mut query = Package::find()
|
|
||||||
.filter(package::Column::RepoId.eq(repo_id))
|
|
||||||
.filter(package::Column::Name.eq(name))
|
|
||||||
.filter(package::Column::Arch.eq(arch));
|
|
||||||
|
|
||||||
if let Some(version) = version {
|
|
||||||
query = query.filter(package::Column::Version.eq(version));
|
|
||||||
}
|
|
||||||
|
|
||||||
query.one(&self.conn).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete_packages_with_arch(
|
|
||||||
&self,
|
|
||||||
repo_id: i32,
|
|
||||||
arch: &str,
|
|
||||||
) -> Result<DeleteResult> {
|
|
||||||
Package::delete_many()
|
|
||||||
.filter(package::Column::RepoId.eq(repo_id))
|
|
||||||
.filter(package::Column::Arch.eq(arch))
|
|
||||||
.exec(&self.conn)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn insert_package(
|
|
||||||
&self,
|
|
||||||
repo_id: i32,
|
|
||||||
pkg: crate::repo::package::Package,
|
|
||||||
) -> Result<()> {
|
|
||||||
let info = pkg.info;
|
|
||||||
|
|
||||||
let model = package::ActiveModel {
|
|
||||||
id: NotSet,
|
|
||||||
repo_id: Set(repo_id),
|
|
||||||
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),
|
|
||||||
};
|
|
||||||
|
|
||||||
let pkg_entry = model.insert(&self.conn).await?;
|
|
||||||
|
|
||||||
// Insert all the related tables
|
|
||||||
PackageLicense::insert_many(info.licenses.iter().map(|s| package_license::ActiveModel {
|
|
||||||
package_id: Set(pkg_entry.id),
|
|
||||||
value: Set(s.to_string()),
|
|
||||||
}))
|
|
||||||
.on_empty_do_nothing()
|
|
||||||
.exec(self)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
PackageGroup::insert_many(info.groups.iter().map(|s| package_group::ActiveModel {
|
|
||||||
package_id: Set(pkg_entry.id),
|
|
||||||
value: Set(s.to_string()),
|
|
||||||
}))
|
|
||||||
.on_empty_do_nothing()
|
|
||||||
.exec(self)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
PackageReplaces::insert_many(info.replaces.iter().map(|s| package_replaces::ActiveModel {
|
|
||||||
package_id: Set(pkg_entry.id),
|
|
||||||
value: Set(s.to_string()),
|
|
||||||
}))
|
|
||||||
.on_empty_do_nothing()
|
|
||||||
.exec(self)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
PackageConflicts::insert_many(info.conflicts.iter().map(|s| {
|
|
||||||
package_conflicts::ActiveModel {
|
|
||||||
package_id: Set(pkg_entry.id),
|
|
||||||
value: Set(s.to_string()),
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
.on_empty_do_nothing()
|
|
||||||
.exec(self)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
PackageProvides::insert_many(info.provides.iter().map(|s| package_provides::ActiveModel {
|
|
||||||
package_id: Set(pkg_entry.id),
|
|
||||||
value: Set(s.to_string()),
|
|
||||||
}))
|
|
||||||
.on_empty_do_nothing()
|
|
||||||
.exec(self)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
PackageFile::insert_many(pkg.files.iter().map(|s| package_file::ActiveModel {
|
|
||||||
package_id: Set(pkg_entry.id),
|
|
||||||
value: Set(s.display().to_string()),
|
|
||||||
}))
|
|
||||||
.on_empty_do_nothing()
|
|
||||||
.exec(self)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let deps = info
|
|
||||||
.depends
|
|
||||||
.iter()
|
|
||||||
.map(|d| (PackageDepend::Depend, d))
|
|
||||||
.chain(info.makedepends.iter().map(|d| (PackageDepend::Make, d)))
|
|
||||||
.chain(info.checkdepends.iter().map(|d| (PackageDepend::Check, d)))
|
|
||||||
.chain(info.optdepends.iter().map(|d| (PackageDepend::Opt, d)))
|
|
||||||
.map(|(t, s)| package_depends::ActiveModel {
|
|
||||||
package_id: Set(pkg_entry.id),
|
|
||||||
r#type: Set(t),
|
|
||||||
value: Set(s.to_string()),
|
|
||||||
});
|
|
||||||
|
|
||||||
PackageDepends::insert_many(deps)
|
|
||||||
.on_empty_do_nothing()
|
|
||||||
.exec(self)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn full_package(&self, id: i32) -> Result<Option<FullPackage>> {
|
|
||||||
if let Some(entry) = self.package(id).await? {
|
|
||||||
let licenses = entry
|
|
||||||
.find_related(PackageLicense)
|
|
||||||
.all(self)
|
|
||||||
.await?
|
|
||||||
.into_iter()
|
|
||||||
.map(|e| e.value)
|
|
||||||
.collect();
|
|
||||||
let groups = entry
|
|
||||||
.find_related(PackageGroup)
|
|
||||||
.all(self)
|
|
||||||
.await?
|
|
||||||
.into_iter()
|
|
||||||
.map(|e| e.value)
|
|
||||||
.collect();
|
|
||||||
let replaces = entry
|
|
||||||
.find_related(PackageReplaces)
|
|
||||||
.all(self)
|
|
||||||
.await?
|
|
||||||
.into_iter()
|
|
||||||
.map(|e| e.value)
|
|
||||||
.collect();
|
|
||||||
let provides = entry
|
|
||||||
.find_related(PackageProvides)
|
|
||||||
.all(self)
|
|
||||||
.await?
|
|
||||||
.into_iter()
|
|
||||||
.map(|e| e.value)
|
|
||||||
.collect();
|
|
||||||
let depends = entry
|
|
||||||
.find_related(PackageDepends)
|
|
||||||
.all(self)
|
|
||||||
.await?
|
|
||||||
.into_iter()
|
|
||||||
.map(|e| (e.r#type, e.value))
|
|
||||||
.collect();
|
|
||||||
let files = entry
|
|
||||||
.find_related(PackageFile)
|
|
||||||
.all(self)
|
|
||||||
.await?
|
|
||||||
.into_iter()
|
|
||||||
.map(|e| e.value)
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
Ok(Some(FullPackage {
|
|
||||||
entry,
|
|
||||||
licenses,
|
|
||||||
groups,
|
|
||||||
replaces,
|
|
||||||
provides,
|
|
||||||
depends,
|
|
||||||
files,
|
|
||||||
}))
|
|
||||||
} else {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -10,7 +10,6 @@ pub type Result<T> = std::result::Result<T, ServerError>;
|
||||||
pub enum ServerError {
|
pub enum ServerError {
|
||||||
IO(io::Error),
|
IO(io::Error),
|
||||||
Axum(axum::Error),
|
Axum(axum::Error),
|
||||||
Db(sea_orm::DbErr),
|
|
||||||
Status(StatusCode),
|
Status(StatusCode),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -20,7 +19,6 @@ impl fmt::Display for ServerError {
|
||||||
ServerError::IO(err) => write!(fmt, "{}", err),
|
ServerError::IO(err) => write!(fmt, "{}", err),
|
||||||
ServerError::Axum(err) => write!(fmt, "{}", err),
|
ServerError::Axum(err) => write!(fmt, "{}", err),
|
||||||
ServerError::Status(status) => write!(fmt, "{}", status),
|
ServerError::Status(status) => write!(fmt, "{}", status),
|
||||||
ServerError::Db(err) => write!(fmt, "{}", err),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -35,10 +33,6 @@ impl IntoResponse for ServerError {
|
||||||
ServerError::IO(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
ServerError::IO(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
||||||
ServerError::Axum(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
ServerError::Axum(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
||||||
ServerError::Status(status) => status.into_response(),
|
ServerError::Status(status) => status.into_response(),
|
||||||
ServerError::Db(sea_orm::DbErr::RecordNotFound(_)) => {
|
|
||||||
StatusCode::NOT_FOUND.into_response()
|
|
||||||
}
|
|
||||||
ServerError::Db(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -66,9 +60,3 @@ impl From<StatusCode> for ServerError {
|
||||||
Self::Status(status)
|
Self::Status(status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<sea_orm::DbErr> for ServerError {
|
|
||||||
fn from(err: sea_orm::DbErr) -> Self {
|
|
||||||
ServerError::Db(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
mod api;
|
|
||||||
mod cli;
|
mod cli;
|
||||||
pub mod db;
|
|
||||||
mod error;
|
mod error;
|
||||||
mod repo;
|
mod repo;
|
||||||
|
|
||||||
|
|
@ -12,21 +10,18 @@ use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
data_dir: PathBuf,
|
|
||||||
repo_dir: PathBuf,
|
repo_dir: PathBuf,
|
||||||
pkg_dir: PathBuf,
|
pkg_dir: PathBuf,
|
||||||
api_key: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Global {
|
pub struct Global {
|
||||||
config: Config,
|
config: Config,
|
||||||
repo_manager: Arc<RwLock<RepoGroupManager>>,
|
repo_manager: Arc<RwLock<RepoGroupManager>>,
|
||||||
db: db::RieterDb,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> crate::Result<()> {
|
async fn main() {
|
||||||
let cli = cli::Cli::parse();
|
let cli = cli::Cli::parse();
|
||||||
cli.run().await
|
cli.run().await;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,13 +65,9 @@ impl RepoGroupManager {
|
||||||
// The desc file needs to be added to both archives
|
// The desc file needs to be added to both archives
|
||||||
let path_in_tar = PathBuf::from(entry.file_name()).join("desc");
|
let path_in_tar = PathBuf::from(entry.file_name()).join("desc");
|
||||||
let src_path = entry.path().join("desc");
|
let src_path = entry.path().join("desc");
|
||||||
let metadata = src_path.metadata()?;
|
|
||||||
|
|
||||||
let mut ar_entry = WriteEntry::new();
|
let mut ar_entry = WriteEntry::new();
|
||||||
ar_entry.set_pathname(&path_in_tar);
|
ar_entry.set_pathname(&path_in_tar);
|
||||||
// These small text files will definitely fit inside an i64
|
|
||||||
ar_entry.set_size(metadata.len().try_into().unwrap());
|
|
||||||
ar_entry.set_filetype(libarchive::archive::FileType::RegularFile);
|
|
||||||
ar_entry.set_mode(0o100644);
|
ar_entry.set_mode(0o100644);
|
||||||
|
|
||||||
ar_db.append_path(&mut ar_entry, &src_path)?;
|
ar_db.append_path(&mut ar_entry, &src_path)?;
|
||||||
|
|
@ -80,14 +76,10 @@ impl RepoGroupManager {
|
||||||
// The files file is only required in the files database
|
// The files file is only required in the files database
|
||||||
let path_in_tar = PathBuf::from(entry.file_name()).join("files");
|
let path_in_tar = PathBuf::from(entry.file_name()).join("files");
|
||||||
let src_path = entry.path().join("files");
|
let src_path = entry.path().join("files");
|
||||||
let metadata = src_path.metadata()?;
|
|
||||||
|
|
||||||
let mut ar_entry = WriteEntry::new();
|
let mut ar_entry = WriteEntry::new();
|
||||||
ar_entry.set_filetype(libarchive::archive::FileType::RegularFile);
|
|
||||||
ar_entry.set_pathname(&path_in_tar);
|
ar_entry.set_pathname(&path_in_tar);
|
||||||
ar_entry.set_mode(0o100644);
|
ar_entry.set_mode(0o100644);
|
||||||
// These small text files will definitely fit inside an i64
|
|
||||||
ar_entry.set_size(metadata.len().try_into().unwrap());
|
|
||||||
|
|
||||||
ar_files.append_path(&mut ar_entry, src_path)?;
|
ar_files.append_path(&mut ar_entry, src_path)?;
|
||||||
}
|
}
|
||||||
|
|
@ -112,12 +104,9 @@ impl RepoGroupManager {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
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)?;
|
|
||||||
|
|
||||||
self.add_pkg(repo, &pkg)?;
|
self.add_pkg(repo, &pkg)?;
|
||||||
|
|
||||||
|
|
@ -129,17 +118,11 @@ impl RepoGroupManager {
|
||||||
.join(pkg.file_name());
|
.join(pkg.file_name());
|
||||||
|
|
||||||
fs::create_dir_all(dest_pkg_path.parent().unwrap())?;
|
fs::create_dir_all(dest_pkg_path.parent().unwrap())?;
|
||||||
fs::rename(&path, dest_pkg_path)?;
|
fs::rename(&path, dest_pkg_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.
|
||||||
pub fn add_pkg(&mut self, repo: &str, pkg: &Package) -> io::Result<()> {
|
pub fn add_pkg(&mut self, repo: &str, pkg: &Package) -> io::Result<()> {
|
||||||
// TODO
|
|
||||||
// * if arch is "any", check if package doesn't already exist for other architecture
|
|
||||||
// * if arch isn't "any", check if package doesn't already exist for "any" architecture
|
|
||||||
|
|
||||||
// We first remove any existing version of the package
|
// We first remove any existing version of the package
|
||||||
self.remove_pkg(repo, &pkg.info.arch, &pkg.info.name, false)?;
|
self.remove_pkg(repo, &pkg.info.arch, &pkg.info.name, false)?;
|
||||||
|
|
||||||
|
|
@ -263,49 +246,4 @@ impl RepoGroupManager {
|
||||||
|
|
||||||
Ok(false)
|
Ok(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wrapper around `remove_pkg` that accepts a path relative to the package directory to a
|
|
||||||
/// package archive.
|
|
||||||
pub fn remove_pkg_from_path<P: AsRef<Path>>(
|
|
||||||
&mut self,
|
|
||||||
path: P,
|
|
||||||
sync: bool,
|
|
||||||
) -> io::Result<Option<(String, String, String, String)>> {
|
|
||||||
let path = path.as_ref();
|
|
||||||
let components: Vec<_> = path.iter().collect();
|
|
||||||
|
|
||||||
if let [repo, _arch, file_name] = components[..] {
|
|
||||||
let full_path = self.pkg_dir.join(path);
|
|
||||||
|
|
||||||
if full_path.try_exists()? {
|
|
||||||
let file_name = file_name.to_string_lossy();
|
|
||||||
let (name, version, release, arch) = parse_pkg_filename(&file_name);
|
|
||||||
|
|
||||||
let metadata_dir_name = format!("{}-{}-{}", name, version, release);
|
|
||||||
|
|
||||||
// Remove package archive and entry in database
|
|
||||||
fs::remove_file(full_path)?;
|
|
||||||
fs::remove_dir_all(self.repo_dir.join(repo).join(arch).join(metadata_dir_name))?;
|
|
||||||
|
|
||||||
if sync {
|
|
||||||
if arch == ANY_ARCH {
|
|
||||||
self.sync_all(&repo.to_string_lossy())?;
|
|
||||||
} else {
|
|
||||||
self.sync(&repo.to_string_lossy(), arch)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Some((
|
|
||||||
name,
|
|
||||||
version.to_string(),
|
|
||||||
release.to_string(),
|
|
||||||
arch.to_string(),
|
|
||||||
)))
|
|
||||||
} else {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
mod manager;
|
mod manager;
|
||||||
pub mod package;
|
mod package;
|
||||||
|
|
||||||
pub use manager::RepoGroupManager;
|
pub use manager::RepoGroupManager;
|
||||||
|
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
use axum::body::Body;
|
use axum::body::Body;
|
||||||
use axum::extract::{BodyStream, Path, State};
|
use axum::extract::{BodyStream, Path, State};
|
||||||
use axum::http::Request;
|
use axum::http::Request;
|
||||||
|
|
@ -13,38 +11,51 @@ use axum::response::IntoResponse;
|
||||||
use axum::routing::{delete, post};
|
use axum::routing::{delete, post};
|
||||||
use axum::Router;
|
use axum::Router;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use sea_orm::ModelTrait;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::{fs, io::AsyncWriteExt};
|
use tokio::{fs, io::AsyncWriteExt};
|
||||||
use tower::util::ServiceExt;
|
use tower::util::ServiceExt;
|
||||||
use tower_http::services::{ServeDir, ServeFile};
|
use tower_http::services::{ServeDir, ServeFile};
|
||||||
use tower_http::validate_request::ValidateRequestHeaderLayer;
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
const DB_FILE_EXTS: [&str; 4] = [".db", ".files", ".db.tar.gz", ".files.tar.gz"];
|
pub fn router() -> Router<crate::Global> {
|
||||||
|
|
||||||
pub fn router(api_key: &str) -> Router<crate::Global> {
|
|
||||||
Router::new()
|
Router::new()
|
||||||
.route(
|
.route("/:repo", post(post_package_archive).delete(delete_repo))
|
||||||
"/:repo",
|
.route("/:repo/:arch", delete(delete_arch_repo))
|
||||||
post(post_package_archive)
|
|
||||||
.delete(delete_repo)
|
|
||||||
.route_layer(ValidateRequestHeaderLayer::bearer(api_key)),
|
|
||||||
)
|
|
||||||
.route(
|
|
||||||
"/:repo/:arch",
|
|
||||||
delete(delete_arch_repo).route_layer(ValidateRequestHeaderLayer::bearer(api_key)),
|
|
||||||
)
|
|
||||||
// Routes added after the layer do not get that layer applied, so the GET requests will not
|
|
||||||
// be authorized
|
|
||||||
.route(
|
.route(
|
||||||
"/:repo/:arch/:filename",
|
"/:repo/:arch/:filename",
|
||||||
delete(delete_package)
|
delete(delete_package).get(get_file),
|
||||||
.route_layer(ValidateRequestHeaderLayer::bearer(api_key))
|
|
||||||
.get(get_file),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn post_package_archive(
|
||||||
|
State(global): State<crate::Global>,
|
||||||
|
Path(repo): Path<String>,
|
||||||
|
mut body: BodyStream,
|
||||||
|
) -> crate::Result<()> {
|
||||||
|
// We first stream the uploaded file to disk
|
||||||
|
let uuid: uuid::fmt::Simple = Uuid::new_v4().into();
|
||||||
|
let path = global.config.pkg_dir.join(uuid.to_string());
|
||||||
|
let mut f = fs::File::create(&path).await?;
|
||||||
|
|
||||||
|
while let Some(chunk) = body.next().await {
|
||||||
|
f.write_all(&chunk?).await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let clone = Arc::clone(&global.repo_manager);
|
||||||
|
let path_clone = path.clone();
|
||||||
|
let res = tokio::task::spawn_blocking(move || {
|
||||||
|
clone.write().unwrap().add_pkg_from_path(&repo, &path_clone)
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
// Remove the downloaded file if the adding failed
|
||||||
|
if res.is_err() {
|
||||||
|
let _ = tokio::fs::remove_file(path).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(res?)
|
||||||
|
}
|
||||||
|
|
||||||
/// Serve the package archive files and database archives. If files are requested for an
|
/// Serve the package archive files and database archives. If files are requested for an
|
||||||
/// architecture that does not have any explicit packages, a repository containing only "any" files
|
/// architecture that does not have any explicit packages, a repository containing only "any" files
|
||||||
/// is returned.
|
/// is returned.
|
||||||
|
|
@ -56,9 +67,9 @@ async fn get_file(
|
||||||
let repo_dir = global.config.repo_dir.join(&repo).join(&arch);
|
let repo_dir = global.config.repo_dir.join(&repo).join(&arch);
|
||||||
let repo_exists = tokio::fs::try_exists(&repo_dir).await?;
|
let repo_exists = tokio::fs::try_exists(&repo_dir).await?;
|
||||||
|
|
||||||
let res = if DB_FILE_EXTS.iter().any(|ext| file_name.ends_with(ext)) {
|
let res = if file_name.ends_with(".db") || file_name.ends_with(".db.tar.gz") {
|
||||||
// Append tar extension to ensure we find the file
|
// Append tar extension to ensure we find the file
|
||||||
if !file_name.ends_with(".tar.gz") {
|
if file_name.ends_with(".db") {
|
||||||
file_name.push_str(".tar.gz");
|
file_name.push_str(".tar.gz");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -95,88 +106,16 @@ async fn get_file(
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn post_package_archive(
|
|
||||||
State(global): State<crate::Global>,
|
|
||||||
Path(repo): Path<String>,
|
|
||||||
mut body: BodyStream,
|
|
||||||
) -> crate::Result<()> {
|
|
||||||
// We first stream the uploaded file to disk
|
|
||||||
let uuid: uuid::fmt::Simple = Uuid::new_v4().into();
|
|
||||||
let path = global.config.pkg_dir.join(uuid.to_string());
|
|
||||||
let mut f = fs::File::create(&path).await?;
|
|
||||||
|
|
||||||
while let Some(chunk) = body.next().await {
|
|
||||||
f.write_all(&chunk?).await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let clone = Arc::clone(&global.repo_manager);
|
|
||||||
let path_clone = path.clone();
|
|
||||||
let repo_clone = repo.clone();
|
|
||||||
let res = tokio::task::spawn_blocking(move || {
|
|
||||||
clone
|
|
||||||
.write()
|
|
||||||
.unwrap()
|
|
||||||
.add_pkg_from_path(&repo_clone, &path_clone)
|
|
||||||
})
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
match res {
|
|
||||||
// Insert the newly added package into the database
|
|
||||||
Ok(pkg) => {
|
|
||||||
tracing::info!("Added '{}' to repository '{}'", pkg.file_name(), repo);
|
|
||||||
|
|
||||||
// Query the repo for its ID, or create it if it does not already exist
|
|
||||||
let res = global.db.repo_by_name(&repo).await?;
|
|
||||||
|
|
||||||
let repo_id = if let Some(repo_entity) = res {
|
|
||||||
repo_entity.id
|
|
||||||
} else {
|
|
||||||
global.db.insert_repo(&repo, None).await?.last_insert_id
|
|
||||||
};
|
|
||||||
|
|
||||||
// If the package already exists in the database, we remove it first
|
|
||||||
let res = global
|
|
||||||
.db
|
|
||||||
.package_by_fields(repo_id, &pkg.info.name, None, &pkg.info.arch)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
if let Some(entry) = res {
|
|
||||||
entry.delete(&global.db).await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
global.db.insert_package(repo_id, pkg).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
// Remove the uploaded file and return the error
|
|
||||||
Err(err) => {
|
|
||||||
tokio::fs::remove_file(path).await?;
|
|
||||||
|
|
||||||
Err(err.into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn delete_repo(
|
async fn delete_repo(
|
||||||
State(global): State<crate::Global>,
|
State(global): State<crate::Global>,
|
||||||
Path(repo): Path<String>,
|
Path(repo): Path<String>,
|
||||||
) -> crate::Result<StatusCode> {
|
) -> crate::Result<StatusCode> {
|
||||||
let clone = Arc::clone(&global.repo_manager);
|
let clone = Arc::clone(&global.repo_manager);
|
||||||
|
|
||||||
let repo_clone = repo.clone();
|
|
||||||
let repo_removed =
|
let repo_removed =
|
||||||
tokio::task::spawn_blocking(move || clone.write().unwrap().remove_repo(&repo_clone))
|
tokio::task::spawn_blocking(move || clone.write().unwrap().remove_repo(&repo)).await??;
|
||||||
.await??;
|
|
||||||
|
|
||||||
if repo_removed {
|
if repo_removed {
|
||||||
let res = global.db.repo_by_name(&repo).await?;
|
|
||||||
|
|
||||||
if let Some(repo_entry) = res {
|
|
||||||
repo_entry.delete(&global.db).await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
tracing::info!("Removed repository '{}'", repo);
|
|
||||||
|
|
||||||
Ok(StatusCode::OK)
|
Ok(StatusCode::OK)
|
||||||
} else {
|
} else {
|
||||||
Ok(StatusCode::NOT_FOUND)
|
Ok(StatusCode::NOT_FOUND)
|
||||||
|
|
@ -189,27 +128,11 @@ async fn delete_arch_repo(
|
||||||
) -> crate::Result<StatusCode> {
|
) -> crate::Result<StatusCode> {
|
||||||
let clone = Arc::clone(&global.repo_manager);
|
let clone = Arc::clone(&global.repo_manager);
|
||||||
|
|
||||||
let arch_clone = arch.clone();
|
let repo_removed =
|
||||||
let repo_clone = repo.clone();
|
tokio::task::spawn_blocking(move || clone.write().unwrap().remove_repo_arch(&repo, &arch))
|
||||||
let repo_removed = tokio::task::spawn_blocking(move || {
|
.await??;
|
||||||
clone
|
|
||||||
.write()
|
|
||||||
.unwrap()
|
|
||||||
.remove_repo_arch(&repo_clone, &arch_clone)
|
|
||||||
})
|
|
||||||
.await??;
|
|
||||||
|
|
||||||
if repo_removed {
|
if repo_removed {
|
||||||
let res = global.db.repo_by_name(&repo).await?;
|
|
||||||
|
|
||||||
if let Some(repo_entry) = res {
|
|
||||||
global
|
|
||||||
.db
|
|
||||||
.delete_packages_with_arch(repo_entry.id, &arch)
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
tracing::info!("Removed architecture '{}' from repository '{}'", arch, repo);
|
|
||||||
|
|
||||||
Ok(StatusCode::OK)
|
Ok(StatusCode::OK)
|
||||||
} else {
|
} else {
|
||||||
Ok(StatusCode::NOT_FOUND)
|
Ok(StatusCode::NOT_FOUND)
|
||||||
|
|
@ -220,35 +143,24 @@ async fn delete_package(
|
||||||
State(global): State<crate::Global>,
|
State(global): State<crate::Global>,
|
||||||
Path((repo, arch, file_name)): Path<(String, String, String)>,
|
Path((repo, arch, file_name)): Path<(String, String, String)>,
|
||||||
) -> crate::Result<StatusCode> {
|
) -> crate::Result<StatusCode> {
|
||||||
let clone = Arc::clone(&global.repo_manager);
|
let name_parts = file_name.split('-').collect::<Vec<_>>();
|
||||||
let path = PathBuf::from(&repo).join(arch).join(&file_name);
|
|
||||||
|
|
||||||
let res = tokio::task::spawn_blocking(move || {
|
// Package archive files use the naming scheme pkgname-pkgver-pkgrel-arch, so a valid
|
||||||
clone.write().unwrap().remove_pkg_from_path(path, true)
|
// name contains at least 4 dash-separated sections
|
||||||
|
if name_parts.len() < 4 {
|
||||||
|
return Ok(StatusCode::NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
let name = name_parts[..name_parts.len() - 3].join("-");
|
||||||
|
|
||||||
|
let clone = Arc::clone(&global.repo_manager);
|
||||||
|
|
||||||
|
let pkg_removed = tokio::task::spawn_blocking(move || {
|
||||||
|
clone.write().unwrap().remove_pkg(&repo, &arch, &name, true)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
if let Some((name, version, release, arch)) = res {
|
if pkg_removed {
|
||||||
let res = global.db.repo_by_name(&repo).await?;
|
|
||||||
|
|
||||||
if let Some(repo_entry) = res {
|
|
||||||
let res = global
|
|
||||||
.db
|
|
||||||
.package_by_fields(
|
|
||||||
repo_entry.id,
|
|
||||||
&name,
|
|
||||||
Some(&format!("{}-{}", version, release)),
|
|
||||||
&arch,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
if let Some(entry) = res {
|
|
||||||
entry.delete(&global.db).await?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tracing::info!("Removed '{}' from repository '{}'", file_name, repo);
|
|
||||||
|
|
||||||
Ok(StatusCode::OK)
|
Ok(StatusCode::OK)
|
||||||
} else {
|
} else {
|
||||||
Ok(StatusCode::NOT_FOUND)
|
Ok(StatusCode::NOT_FOUND)
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,13 @@
|
||||||
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, Clone)]
|
#[derive(Debug)]
|
||||||
pub struct Package {
|
pub struct Package {
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
pub info: PkgInfo,
|
pub info: PkgInfo,
|
||||||
|
|
@ -19,20 +15,20 @@ pub struct Package {
|
||||||
pub compression: ReadFilter,
|
pub compression: ReadFilter,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
#[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…
Reference in New Issue