diff --git a/src/installer/file.rs b/src/installer/file.rs index 459a601..8833ca0 100644 --- a/src/installer/file.rs +++ b/src/installer/file.rs @@ -71,6 +71,9 @@ fn file_type_for(file: &FileInfo) -> Option { if file_name.ends_with(".zip") { return Some(FileType::ZipArchive); } + if file_name.ends_with(".7z") { + return Some(FileType::SevenZipArchive); + } if is_elf_file(&file.path) || Path::new(&file_name).extension().is_none() || file_name.ends_with(".appimage") @@ -142,6 +145,7 @@ mod tests { #[test_case("file.exe", FileType::ExecutableFile)] #[test_case("file", FileType::ExecutableFile)] #[test_case("file.AppImage", FileType::ExecutableFile)] + #[test_case("file.7z", FileType::SevenZipArchive)] fn supported_file(file_name: &str, expected_file_type: FileType) { let file_info = any_file_info(file_name); let result = validate_file(file_info); diff --git a/src/installer/install.rs b/src/installer/install.rs index 7702a7b..5349714 100644 --- a/src/installer/install.rs +++ b/src/installer/install.rs @@ -6,6 +6,7 @@ use crate::installer::executable::Executable; use crate::installer::executable_file_installer::ExecutableFileInstaller; use crate::installer::file::{validate_file, Compression, FileInfo, FileType, SupportedFileInfo}; use crate::installer::result::InstallerResult; +use crate::installer::seven_zip_archive_installer::SevenZipArchiveInstaller; use crate::installer::tar_archive_installer::TarArchiveInstaller; use crate::installer::zip_archive_installer::ZipArchiveInstaller; use std::path::Path; @@ -38,7 +39,7 @@ fn find_installer_for( FileType::TarArchive(Compression::Xz) => TarArchiveInstaller::xz, FileType::TarArchive(Compression::Bz2) => TarArchiveInstaller::bz2, FileType::ZipArchive => ZipArchiveInstaller::run, - FileType::SevenZipArchive => todo!(), + FileType::SevenZipArchive => SevenZipArchiveInstaller::run, FileType::CompressedFile(Compression::Gz) => CompressedFileInstaller::gz, FileType::CompressedFile(Compression::Xz) => CompressedFileInstaller::xz, FileType::CompressedFile(Compression::Bz2) => CompressedFileInstaller::bz2, diff --git a/src/installer/mod.rs b/src/installer/mod.rs index b794800..5197c6e 100644 --- a/src/installer/mod.rs +++ b/src/installer/mod.rs @@ -9,6 +9,7 @@ mod executable_file_installer; mod file; mod install; mod result; +mod seven_zip_archive_installer; mod tar_archive_installer; mod zip_archive_installer; diff --git a/src/installer/seven_zip_archive_installer.rs b/src/installer/seven_zip_archive_installer.rs new file mode 100644 index 0000000..1ca818e --- /dev/null +++ b/src/installer/seven_zip_archive_installer.rs @@ -0,0 +1,33 @@ +use crate::installer::archive_installer::ArchiveInstaller; +use crate::installer::command::exec_command; +use crate::installer::destination::Destination; +use crate::installer::error::InstallError; +use crate::installer::executable::Executable; +use crate::installer::file::SupportedFileInfo; +use crate::installer::result::InstallerResult; +use std::path::Path; +use std::process::Command; + +const _7Z: &str = "7z"; + +pub struct SevenZipArchiveInstaller; + +impl SevenZipArchiveInstaller { + pub fn run( + file_info: SupportedFileInfo, + destination: Destination, + executable: &Executable, + ) -> InstallerResult { + ArchiveInstaller::run(Self::extract_archive, file_info, destination, executable) + } + + fn extract_archive(source: &Path, temp_dir: &Path) -> Result<(), InstallError> { + exec_command( + _7Z, + Command::new(_7Z) + .arg("x") + .arg(source) + .arg(format!("-o{}", temp_dir.display())), + ) + } +} diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 49d4d29..31c6cba 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -18,6 +18,7 @@ mod install { #[test_case("helloworld.tar.bz2", "helloworld"; "tar bzip2")] #[test_case("helloworld.tar.xz", "helloworld"; "tar xz")] #[test_case("helloworld.zip", "helloworld"; "zip")] + #[test_case("helloworld.7z", "helloworld"; "7zip")] #[test_case("helloworld-compressed-unix.gz", "helloworld-compressed-unix"; "gzip")] #[test_case("helloworld-compressed-unix.bz2", "helloworld-compressed-unix"; "bzip2")] #[test_case("helloworld-compressed-unix.xz", "helloworld-compressed-unix"; "xz")] @@ -45,6 +46,7 @@ mod install { #[cfg(target_os = "windows")] #[test_case("helloworld-windows.tar.gz", "helloworld.exe"; "tar gzip")] #[test_case("helloworld-windows.zip", "helloworld.exe"; "zip")] + #[test_case("helloworld-windows.7z", "helloworld.exe"; "7zip")] #[test_case("helloworld-compressed-windows.gz", "helloworld-compressed-windows"; "gzip")] #[test_case("helloworld-compressed-windows.bz2", "helloworld-compressed-windows"; "bzip2")] #[test_case("helloworld-compressed-windows.xz", "helloworld-compressed-windows"; "xz")]