Compare commits
2 Commits
513a760040
...
32e27978ec
Author | SHA1 | Date |
---|---|---|
Jef Roosens | 32e27978ec | |
Jef Roosens | bf100049b1 |
|
@ -1,4 +1,4 @@
|
||||||
use crate::repo::{MetaRepoMgr, RepoGroupManager};
|
use crate::repo::MetaRepoMgr;
|
||||||
use crate::{Config, Global};
|
use crate::{Config, Global};
|
||||||
|
|
||||||
use axum::extract::FromRef;
|
use axum::extract::FromRef;
|
||||||
|
@ -82,7 +82,6 @@ impl Cli {
|
||||||
|
|
||||||
let config = Config {
|
let config = Config {
|
||||||
data_dir: self.data_dir.clone(),
|
data_dir: self.data_dir.clone(),
|
||||||
api_key: self.api_key.clone(),
|
|
||||||
};
|
};
|
||||||
let repo_manager = MetaRepoMgr::new(&self.data_dir.join("repos"));
|
let repo_manager = MetaRepoMgr::new(&self.data_dir.join("repos"));
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,10 @@ pub struct Filter {
|
||||||
|
|
||||||
impl IntoCondition for Filter {
|
impl IntoCondition for Filter {
|
||||||
fn into_condition(self) -> Condition {
|
fn into_condition(self) -> Condition {
|
||||||
Condition::all().add_option(self.name.map(|name| package::Column::Name.like(name)))
|
Condition::all().add_option(
|
||||||
|
self.name
|
||||||
|
.map(|name| repo::Column::Name.like(format!("%{}%", name))),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ mod repo;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
pub use error::{Result, ServerError};
|
pub use error::{Result, ServerError};
|
||||||
use repo::MetaRepoMgr;
|
use repo::MetaRepoMgr;
|
||||||
use repo::RepoGroupManager;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
@ -15,7 +14,6 @@ use tokio::sync::RwLock;
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
data_dir: PathBuf,
|
data_dir: PathBuf,
|
||||||
api_key: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|
|
@ -1,17 +1,10 @@
|
||||||
use std::io::{self, Write};
|
use std::io;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use tokio::sync::{mpsc, oneshot};
|
|
||||||
|
|
||||||
use libarchive::write::{Builder, FileWriter, WriteEntry};
|
use libarchive::write::{Builder, FileWriter, WriteEntry};
|
||||||
use libarchive::{Entry, WriteFilter, WriteFormat};
|
use libarchive::{Entry, WriteFilter, WriteFormat};
|
||||||
|
|
||||||
enum Message {
|
|
||||||
AppendFilesEntry(oneshot::Sender<io::Result<()>>, String),
|
|
||||||
AppendLine(oneshot::Sender<io::Result<()>>, String),
|
|
||||||
Close(oneshot::Sender<io::Result<()>>),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Struct to abstract away the intrinsics of writing entries to an archive file
|
/// Struct to abstract away the intrinsics of writing entries to an archive file
|
||||||
pub struct RepoArchiveWriter {
|
pub struct RepoArchiveWriter {
|
||||||
ar: Arc<Mutex<FileWriter>>,
|
ar: Arc<Mutex<FileWriter>>,
|
||||||
|
|
|
@ -133,6 +133,51 @@ impl MetaRepoMgr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Remove all packages from the repository with the given arch.
|
||||||
|
pub async fn remove_repo_arch(&self, conn: &DbConn, repo: &str, arch: &str) -> Result<bool> {
|
||||||
|
let repo = db::query::repo::by_name(conn, repo).await?;
|
||||||
|
|
||||||
|
if let Some(repo) = repo {
|
||||||
|
let mut pkgs = repo
|
||||||
|
.find_related(db::Package)
|
||||||
|
.filter(db::package::Column::Arch.eq(arch))
|
||||||
|
.stream(conn)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
while let Some(pkg) = pkgs.next().await.transpose()? {
|
||||||
|
let path = self
|
||||||
|
.repo_dir
|
||||||
|
.join(&repo.name)
|
||||||
|
.join(super::package::filename(&pkg));
|
||||||
|
tokio::fs::remove_file(path).await?;
|
||||||
|
|
||||||
|
pkg.delete(conn).await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
tokio::fs::remove_file(
|
||||||
|
self.repo_dir
|
||||||
|
.join(&repo.name)
|
||||||
|
.join(format!("{}.db.tar.gz", arch)),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
tokio::fs::remove_file(
|
||||||
|
self.repo_dir
|
||||||
|
.join(&repo.name)
|
||||||
|
.join(format!("{}.files.tar.gz", arch)),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
// If we removed all "any" packages, we need to resync all databases
|
||||||
|
if arch == ANY_ARCH {
|
||||||
|
self.generate_archives_all(conn, &repo.name).await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(true)
|
||||||
|
} else {
|
||||||
|
Ok(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn remove_pkg(
|
pub async fn remove_pkg(
|
||||||
&self,
|
&self,
|
||||||
conn: &DbConn,
|
conn: &DbConn,
|
||||||
|
|
|
@ -3,13 +3,9 @@ mod manager;
|
||||||
mod manager_new;
|
mod manager_new;
|
||||||
pub mod package;
|
pub mod package;
|
||||||
|
|
||||||
pub use manager::RepoGroupManager;
|
|
||||||
pub use manager_new::MetaRepoMgr;
|
pub use manager_new::MetaRepoMgr;
|
||||||
use tokio_util::io::StreamReader;
|
use tokio_util::io::StreamReader;
|
||||||
|
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
use crate::db;
|
|
||||||
use axum::body::Body;
|
use axum::body::Body;
|
||||||
use axum::extract::{Path, State};
|
use axum::extract::{Path, State};
|
||||||
use axum::http::Request;
|
use axum::http::Request;
|
||||||
|
@ -18,17 +14,9 @@ use axum::response::IntoResponse;
|
||||||
use axum::routing::{delete, post};
|
use axum::routing::{delete, post};
|
||||||
use axum::Router;
|
use axum::Router;
|
||||||
use futures::TryStreamExt;
|
use futures::TryStreamExt;
|
||||||
use futures::{Stream, StreamExt};
|
|
||||||
use regex::Regex;
|
|
||||||
use sea_orm::ModelTrait;
|
|
||||||
use std::sync::Arc;
|
|
||||||
use tokio::{fs, io::AsyncWriteExt};
|
|
||||||
use tower::util::ServiceExt;
|
use tower::util::ServiceExt;
|
||||||
use tower_http::services::{ServeDir, ServeFile};
|
use tower_http::services::ServeFile;
|
||||||
use tower_http::validate_request::ValidateRequestHeaderLayer;
|
use tower_http::validate_request::ValidateRequestHeaderLayer;
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
const DB_FILE_EXTS: [&str; 4] = [".db", ".files", ".db.tar.gz", ".files.tar.gz"];
|
|
||||||
|
|
||||||
pub fn router(api_key: &str) -> Router<crate::Global> {
|
pub fn router(api_key: &str) -> Router<crate::Global> {
|
||||||
Router::new()
|
Router::new()
|
||||||
|
@ -120,31 +108,20 @@ async fn delete_arch_repo(
|
||||||
State(global): State<crate::Global>,
|
State(global): State<crate::Global>,
|
||||||
Path((repo, arch)): Path<(String, String)>,
|
Path((repo, arch)): Path<(String, String)>,
|
||||||
) -> crate::Result<StatusCode> {
|
) -> crate::Result<StatusCode> {
|
||||||
Ok(StatusCode::NOT_FOUND)
|
let repo_removed = global
|
||||||
//let clone = Arc::clone(&global.repo_manager);
|
.repo_manager
|
||||||
//
|
.write()
|
||||||
//let arch_clone = arch.clone();
|
.await
|
||||||
//let repo_clone = repo.clone();
|
.remove_repo_arch(&global.db, &repo, &arch)
|
||||||
//let repo_removed = tokio::task::spawn_blocking(move || {
|
.await?;
|
||||||
// clone
|
|
||||||
// .write()
|
if repo_removed {
|
||||||
// .unwrap()
|
tracing::info!("Removed arch '{}' from repository '{}'", arch, repo);
|
||||||
// .remove_repo_arch(&repo_clone, &arch_clone)
|
|
||||||
//})
|
Ok(StatusCode::OK)
|
||||||
//.await??;
|
} else {
|
||||||
//
|
Ok(StatusCode::NOT_FOUND)
|
||||||
//if repo_removed {
|
}
|
||||||
// let res = db::query::repo::by_name(&global.db, &repo).await?;
|
|
||||||
//
|
|
||||||
// if let Some(repo_entry) = res {
|
|
||||||
// db::query::package::delete_with_arch(&global.db, repo_entry.id, &arch).await?;
|
|
||||||
// }
|
|
||||||
// tracing::info!("Removed architecture '{}' from repository '{}'", arch, repo);
|
|
||||||
//
|
|
||||||
// Ok(StatusCode::OK)
|
|
||||||
//} else {
|
|
||||||
// Ok(StatusCode::NOT_FOUND)
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete_package(
|
async fn delete_package(
|
||||||
|
|
Loading…
Reference in New Issue