-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
repo init function takes path and repo name
- Loading branch information
1 parent
0c5d447
commit 01a5b22
Showing
3 changed files
with
22 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} | ||
} |