From 0c5d4479d1eaef728ade729e32508d9db5cdc461 Mon Sep 17 00:00:00 2001 From: lukas-heilgenbrunner Date: Mon, 12 Aug 2024 09:01:31 +0200 Subject: [PATCH] outsource repo init into pacman utils lib --- backend/Cargo.lock | 2 -- backend/Cargo.toml | 2 -- backend/src/main.rs | 3 +-- backend/src/pacman-repo-utils/Cargo.toml | 1 + backend/src/pacman-repo-utils/src/lib.rs | 7 +++++++ .../src/repo_init.rs} | 16 ++++++++-------- backend/src/repo/mod.rs | 1 - 7 files changed, 17 insertions(+), 15 deletions(-) rename backend/src/{repo/init.rs => pacman-repo-utils/src/repo_init.rs} (86%) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index f10f373..6ae3a59 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -235,7 +235,6 @@ dependencies = [ "aur-rs", "bigdecimal 0.4.5", "env_logger", - "flate2", "log", "pacman-repo-utils", "reqwest 0.12.5", @@ -247,7 +246,6 @@ dependencies = [ "sea-orm-migration", "serde", "shiplift", - "tar", "tokio", ] diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 19f1158..ff22dec 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -11,8 +11,6 @@ tokio = "1.38.0" anyhow = "1.0.76" reqwest = { version = "0.12.5", features = ["blocking", "gzip"] } -flate2 = "1.0.30" -tar = "0.4.41" rocket = "0.5.1" rocket_okapi = { features = ["swagger"], git = "https://github.com/beyera/okapi.git", branch = "beyera/update-rocket-0.5.1" } diff --git a/backend/src/main.rs b/backend/src/main.rs index 162ecc2..4962786 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -11,7 +11,6 @@ use crate::api::init::{init_api, init_repo}; use crate::builder::init::init_build_queue; use crate::builder::types::Action; use crate::db::init::init_db; -use crate::repo::init::init_repo_files; use crate::scheduler::aur_version_update::start_aur_version_checking; use crate::utils::logger::init_logger; use log::{info, warn}; @@ -37,7 +36,7 @@ async fn main() { .map_err(|e| format!("Failed to initialize database: {}", e)) .unwrap(); - init_repo_files().await.unwrap(); + pacman_repo_utils::init_repo().unwrap(); let build_queue_handle = init_build_queue(db.clone(), tx.clone()); let version_check_handle = start_aur_version_checking(db.clone()); diff --git a/backend/src/pacman-repo-utils/Cargo.toml b/backend/src/pacman-repo-utils/Cargo.toml index 6072708..148c083 100644 --- a/backend/src/pacman-repo-utils/Cargo.toml +++ b/backend/src/pacman-repo-utils/Cargo.toml @@ -1,5 +1,6 @@ [package] name = "pacman-repo-utils" +description = "Plug in replacement for repo-add pacman tools" version = "0.1.0" edition = "2021" diff --git a/backend/src/pacman-repo-utils/src/lib.rs b/backend/src/pacman-repo-utils/src/lib.rs index 43b2ab0..6afcecc 100644 --- a/backend/src/pacman-repo-utils/src/lib.rs +++ b/backend/src/pacman-repo-utils/src/lib.rs @@ -2,7 +2,10 @@ mod pkginfo; mod repo_add; mod repo_database; mod repo_remove; +mod repo_init; + use crate::repo_add::repo_add_impl; +use crate::repo_init::init_repo_impl; use crate::repo_remove::repo_remove_impl; pub fn repo_add(pkgfile: &str, db_archive: String, files_archive: String) -> anyhow::Result<()> { @@ -16,3 +19,7 @@ pub fn repo_remove( ) -> anyhow::Result<()> { repo_remove_impl(filename, db_archive, files_archive) } + +pub fn init_repo() -> anyhow::Result<()>{ + init_repo_impl() +} \ No newline at end of file diff --git a/backend/src/repo/init.rs b/backend/src/pacman-repo-utils/src/repo_init.rs similarity index 86% rename from backend/src/repo/init.rs rename to backend/src/pacman-repo-utils/src/repo_init.rs index f2efa84..54a04e4 100644 --- a/backend/src/repo/init.rs +++ b/backend/src/pacman-repo-utils/src/repo_init.rs @@ -1,13 +1,15 @@ -use anyhow::anyhow; -use flate2::read::GzEncoder; -use flate2::Compression; use std::fs; use std::fs::File; -use tokio::fs::symlink; +use std::os::unix::fs::symlink; +use anyhow::anyhow; +use flate2::Compression; +use flate2::read::GzEncoder; +use log::info; -pub async fn init_repo_files() -> anyhow::Result<()> { +pub fn init_repo_impl() -> anyhow::Result<()>{ // create repo folder if fs::metadata("./repo").is_err() { + info!("Initializing empty pacman Repo archive"); fs::create_dir("./repo")?; let tar_gz = File::create("./repo/repo.db.tar.gz")?; @@ -16,7 +18,6 @@ pub async fn init_repo_files() -> anyhow::Result<()> { tar.finish() .map_err(|_| anyhow!("failed to create repo archive"))?; symlink("repo.db.tar.gz", "./repo/repo.db") - .await .map_err(|_| anyhow!("failed to create repo symlink"))?; let tar_gz = File::create("./repo/repo.files.tar.gz")?; @@ -25,8 +26,7 @@ pub async fn init_repo_files() -> anyhow::Result<()> { tar.finish() .map_err(|_| anyhow!("failed to create repo archive"))?; symlink("repo.files.tar.gz", "./repo/repo.files") - .await .map_err(|_| anyhow!("failed to create repo symlink"))?; } Ok(()) -} +} \ No newline at end of file diff --git a/backend/src/repo/mod.rs b/backend/src/repo/mod.rs index dfb834c..b5614dd 100644 --- a/backend/src/repo/mod.rs +++ b/backend/src/repo/mod.rs @@ -1,2 +1 @@ -pub mod init; pub mod utils;