Skip to content

Commit

Permalink
repo init function takes path and repo name
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas-Heiligenbrunner committed Aug 12, 2024
1 parent 0c5d447 commit 01a5b22
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
3 changes: 2 additions & 1 deletion backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod repo;
mod scheduler;
mod utils;

use std::path::PathBuf;
use crate::api::init::{init_api, init_repo};
use crate::builder::init::init_build_queue;
use crate::builder::types::Action;
Expand Down Expand Up @@ -36,7 +37,7 @@ async fn main() {
.map_err(|e| format!("Failed to initialize database: {}", e))
.unwrap();

pacman_repo_utils::init_repo().unwrap();
pacman_repo_utils::init_repo(&PathBuf::from("./repo"), "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
9 changes: 5 additions & 4 deletions backend/src/pacman-repo-utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
mod pkginfo;
mod repo_add;
mod repo_database;
mod repo_remove;
mod repo_init;
mod repo_remove;

use std::path::PathBuf;
use crate::repo_add::repo_add_impl;
use crate::repo_init::init_repo_impl;
use crate::repo_remove::repo_remove_impl;
Expand All @@ -20,6 +21,6 @@ pub fn repo_remove(
repo_remove_impl(filename, db_archive, files_archive)
}

pub fn init_repo() -> anyhow::Result<()>{
init_repo_impl()
}
pub fn init_repo(path: &PathBuf, name: &str) -> anyhow::Result<()> {
init_repo_impl(path, name)
}
27 changes: 15 additions & 12 deletions backend/src/pacman-repo-utils/src/repo_init.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
use std::fs;
use std::fs::File;
use std::os::unix::fs::symlink;
use anyhow::anyhow;
use flate2::Compression;
use flate2::read::GzEncoder;
use flate2::Compression;
use log::info;
use std::fs;
use std::fs::File;
use std::os::unix::fs::symlink;
use std::path::PathBuf;

pub fn init_repo_impl() -> anyhow::Result<()>{
pub fn init_repo_impl(path: &PathBuf, name: &str) -> anyhow::Result<()> {
// create repo folder
if fs::metadata("./repo").is_err() {
if fs::metadata(path).is_err() {
info!("Initializing empty pacman Repo archive");
fs::create_dir("./repo")?;
fs::create_dir(path)?;

let tar_gz = File::create("./repo/repo.db.tar.gz")?;
let db_file = path.join(format!("{}.db.tar.gz", name));
let tar_gz = File::create(&db_file)?;
let enc = GzEncoder::new(tar_gz, Compression::default());
let mut tar = tar::Builder::new(enc);
tar.finish()
.map_err(|_| anyhow!("failed to create repo archive"))?;
symlink("repo.db.tar.gz", "./repo/repo.db")
symlink(&db_file, path.join(format!("{}.db", name)))
.map_err(|_| anyhow!("failed to create repo symlink"))?;

let tar_gz = File::create("./repo/repo.files.tar.gz")?;
let files_file = path.join(format!("{}.files.tar.gz", name));
let tar_gz = File::create(&files_file)?;
let enc = GzEncoder::new(tar_gz, Compression::default());
let mut tar = tar::Builder::new(enc);
tar.finish()
.map_err(|_| anyhow!("failed to create repo archive"))?;
symlink("repo.files.tar.gz", "./repo/repo.files")
symlink(&files_file, path.join(format!("{}.files", name)))
.map_err(|_| anyhow!("failed to create repo symlink"))?;
}
Ok(())
}
}

0 comments on commit 01a5b22

Please sign in to comment.