Skip to content

Commit

Permalink
outsource repo init into pacman utils lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas-Heiligenbrunner committed Aug 12, 2024
1 parent 65de74c commit 0c5d447
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 15 deletions.
2 changes: 0 additions & 2 deletions backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
3 changes: 1 addition & 2 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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());
Expand Down
1 change: 1 addition & 0 deletions backend/src/pacman-repo-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[package]
name = "pacman-repo-utils"
description = "Plug in replacement for repo-add pacman tools"
version = "0.1.0"
edition = "2021"

Expand Down
7 changes: 7 additions & 0 deletions backend/src/pacman-repo-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand All @@ -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()
}
Original file line number Diff line number Diff line change
@@ -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")?;
Expand All @@ -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")?;
Expand All @@ -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(())
}
}
1 change: 0 additions & 1 deletion backend/src/repo/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
pub mod init;
pub mod utils;

0 comments on commit 0c5d447

Please sign in to comment.