-
-
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.
outsource repo init into pacman utils lib (#41)
* outsource repo init into pacman utils lib * repo init function takes path and repo name * check if files exist and not just folder
- Loading branch information
1 parent
65de74c
commit c19a728
Showing
8 changed files
with
50 additions
and
39 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use anyhow::anyhow; | ||
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(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(&db_file).is_ok() || fs::metadata(&files_file).is_ok() { | ||
info!("Pacman repo archive already exists"); | ||
return Ok(()); | ||
} | ||
|
||
info!("Initializing empty pacman Repo archive"); | ||
fs::create_dir(path)?; | ||
|
||
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(()) | ||
} |
This file was deleted.
Oops, something went wrong.
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,2 +1 @@ | ||
pub mod init; | ||
pub mod utils; |