Skip to content

Commit

Permalink
check if files exist and not just folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas-Heiligenbrunner committed Aug 13, 2024
1 parent 859a4e5 commit ac4f8ec
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions backend/src/pacman-repo-utils/src/repo_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,32 @@ use std::os::unix::fs::symlink;
use std::path::PathBuf;

pub fn init_repo_impl(path: &PathBuf, name: &str) -> anyhow::Result<()> {
let db_file = path.join(format!("{}.db.tar.gz", name));
let files_file = path.join(format!("{}.files.tar.gz", name));

// create repo folder
if fs::metadata(path).is_err() {
info!("Initializing empty pacman Repo archive");
fs::create_dir(path)?;
if fs::metadata(&db_file).is_ok() || fs::metadata(&files_file).is_ok() {
info!("Pacman repo archive already exists");
return Ok(());
}

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(&db_file, path.join(format!("{}.db", name)))
.map_err(|_| anyhow!("failed to create repo symlink"))?;
info!("Initializing empty pacman Repo archive");
fs::create_dir(path)?;

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(&files_file, path.join(format!("{}.files", name)))
.map_err(|_| anyhow!("failed to create repo symlink"))?;
}
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(&db_file, path.join(format!("{}.db", name)))
.map_err(|_| anyhow!("failed to create repo symlink"))?;

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(&files_file, path.join(format!("{}.files", name)))
.map_err(|_| anyhow!("failed to create repo symlink"))?;
Ok(())
}

0 comments on commit ac4f8ec

Please sign in to comment.