summaryrefslogtreecommitdiff
path: root/src/pkgtoolkit
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkgtoolkit')
-rw-r--r--src/pkgtoolkit/pkgtools.rs64
1 files changed, 43 insertions, 21 deletions
diff --git a/src/pkgtoolkit/pkgtools.rs b/src/pkgtoolkit/pkgtools.rs
index 29145d3..0105a11 100644
--- a/src/pkgtoolkit/pkgtools.rs
+++ b/src/pkgtoolkit/pkgtools.rs
@@ -42,7 +42,7 @@ pub struct InstallMeta {
user: String,
group: String,
mode: String,
- //. Cancels the previous fields and installs them using the shell script
+ //! Cancels the previous fields and installs them using the shell script
custom_script: Option<String>,
}
@@ -56,8 +56,10 @@ struct Install {
#[allow(dead_code)]
#[derive(Deserialize, Debug)]
struct Setts {
- env: Option<String>, // Export environment variables if this needed
- test: Option<String>, // Test the package after installation
+ //! Export environment variables if this needed
+ env: Option<String>,
+ //! Test the package after installation
+ test: Option<String>,
}
#[derive(Deserialize, Serialize, Debug)]
@@ -164,15 +166,27 @@ impl Package {
/// * `Err(std::io::Error)` if there's an issue opening, reading, or unpacking the archive.
pub fn extract_archive(path_to_archive: &str) -> Result<(), std::io::Error> {
let config = Config::parse().unwrap();
- create_dir_all(&config.paths.cache_dir)?;
+ let cache_dir = &config.paths.cache_dir;
+ create_dir_all(cache_dir)?;
+
+ // Очистим возможные мета-файлы предыдущих распаковок, чтобы не было утечек состояния
+ for meta_name in ["INSTALL", "SETTS", "BUILD"] {
+ let meta_path = Path::new(cache_dir).join(meta_name);
+ if meta_path.exists() {
+ let _ = fs::remove_file(&meta_path);
+ }
+ }
let file = File::open(path_to_archive)?;
let gz = GzDecoder::new(file);
let mut archive = Archive::new(gz);
- // Unpack directly into the cache directory
- archive.unpack(&config.paths.cache_dir)?;
- Ok(())
+ // Unpack directly into the cache directory. Игнорируем AlreadyExists, чтобы не мешать валидации.
+ match archive.unpack(cache_dir) {
+ Ok(()) => Ok(()),
+ Err(e) if e.kind() == io::ErrorKind::AlreadyExists => Ok(()),
+ Err(e) => Err(e),
+ }
}
/// Load meta information from the .mesk archive.
@@ -289,14 +303,16 @@ impl Package {
///
// TODO: Add meta-files validation here.
pub fn check(path_to_archive: String) -> Result<bool, std::io::Error> {
- // Call the new extraction function
Self::extract_archive(&path_to_archive)?;
- let config = Config::parse().unwrap();
+ let archive_path = Path::new(&path_to_archive);
+ let archive_dir = archive_path
+ .parent()
+ .unwrap_or_else(|| Path::new("."));
- let install_path = Path::new(&config.paths.cache_dir).join("INSTALL");
- let setts_path = Path::new(&config.paths.cache_dir).join("SETTS");
- let build_path = Path::new(&config.paths.cache_dir).join("BUILD");
+ let install_path = archive_dir.join("INSTALL");
+ let setts_path = archive_dir.join("SETTS");
+ let build_path = archive_dir.join("BUILD");
if !install_path.exists() {
return Err(std::io::Error::new(
@@ -338,15 +354,21 @@ impl Package {
let install_content: Result<Install, toml::de::Error> = toml::from_str(&content);
log::info!("Validating arch...");
- if std::env::consts::ARCH
- != install_content
- .as_ref()
- .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e.to_string()))?
- .package
- .arch
- .as_str()
- {
- let pkg_arch = &install_content.unwrap().package.arch; // Safe because of previous check/unwrap
+
+
+ let install_parsed = match install_content {
+ Ok(v) => v,
+ Err(e) => {
+ log::error!("Arch mismatch while parsing INSTALL: {}", e);
+ return Err(std::io::Error::new(
+ std::io::ErrorKind::InvalidData,
+ format!("Arch mismatch: {}", e),
+ ));
+ }
+ };
+
+ if std::env::consts::ARCH != install_parsed.package.arch.as_str() {
+ let pkg_arch = &install_parsed.package.arch;
log::error!(
"Arch mismatch. Package arch: {:?}, Host arch: {}",
pkg_arch,