Skip to content

Commit

Permalink
Refactor decompress_archive and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Duddino committed Oct 6, 2024
1 parent a7ea49b commit 9f6d627
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src-tauri/src/pivx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ use crate::binary::BinaryDefinition;

pub struct PIVXDefinition;

impl BinaryDefinition for PIVXDefinition {
fn decompress_archive(&self, dir: &Path) -> Result<(), PIVXErrors> {
impl PIVXDefinition {
fn inner_decompress_archive(&self, dir: &Path) -> Result<(), PIVXErrors> {
let mut tarball = Archive::new(GzDecoder::new(File::open(dir.join("pivxd.tar.gz"))?));
tarball.unpack(dir)?;
Ok(())
}

fn inner_install_params(&self, dir: &Path) -> Result<(), PIVXErrors> {
let pivx_dir = dir.join("pivx-5.6.1");
let script_path = pivx_dir.join("install-params.sh");
let mut handle = Command::new(script_path)
Expand All @@ -28,6 +32,13 @@ impl BinaryDefinition for PIVXDefinition {
false => Err(PIVXErrors::FetchParamsFailed),
}
}
}

impl BinaryDefinition for PIVXDefinition {
fn decompress_archive(&self, dir: &Path) -> Result<(), PIVXErrors> {
self.inner_decompress_archive(dir)?;
self.inner_install_params(dir)
}

fn get_url(&self) -> &str {
#[cfg(target_os = "linux")]
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/pivx/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod pivx_fetch {
];
file.write_all(&data)?;
let pivx_def = PIVXDefinition;
pivx_def.decompress_archive(&data_dir)?;
pivx_def.inner_decompress_archive(&data_dir)?;

let mut dirs: Vec<_> = std::fs::read_dir(data_dir)?
.filter_map(|d| {
Expand Down

0 comments on commit 9f6d627

Please sign in to comment.