update modules

This commit is contained in:
pivodevat
2025-09-02 20:01:30 +03:00
parent bcb6dcca1d
commit 968216f5f2
11 changed files with 91 additions and 28 deletions

View File

@ -2,19 +2,27 @@ use std::fs;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::process;
use std::os::unix::fs::MetadataExt;
use crate::utils::parser;
use crate::commands::pkglink::pkglink;
use crate::commands::link::link;
pub fn install(repo: &String, pkgname: &String) -> Result<(), bool> {
let var_path = super::get_var_path();
let pkg_md_path = var_path.join(format!("{}/{}.md", repo, pkgname));
let pkg_md_path = var_path.join(format!("{}/{}.md", &repo, &pkgname));
let builded_pkg_md_path = PathBuf::from("/pkg").join(&repo).join(&pkgname).join("build-script.md");
if !pkg_md_path.exists() {
upload_from_repo(&repo, &pkgname, &pkg_md_path)?;
}
if builded_pkg_md_path.exists() {
if fs::metadata(&builded_pkg_md_path).unwrap().ino() == fs::metadata(&pkg_md_path).unwrap().ino() {
println!("package {} already installed in {} repo", &pkgname, &repo);
return Ok(())
}
}
check_build_dependency(&repo, &pkg_md_path)?;
check_run_dependency(&pkg_md_path)?;
@ -23,7 +31,8 @@ pub fn install(repo: &String, pkgname: &String) -> Result<(), bool> {
let src_dir = PathBuf::from("/pkg/src").join(&pkgname);
patch(&pkgname, &src_dir, &pkg_md_path)?;
build(&repo, &pkgname, &src_dir, &pkg_md_path)?;
pkglink(&repo, &pkgname).expect("Failed link package");
link(&repo, &pkgname).expect("Failed link package");
hook(&repo, &pkgname);
config(&src_dir, &pkg_md_path)?;
let src_remove_flag = match std::env::var("pkg_src_remove") {
@ -332,6 +341,19 @@ fn build(
}
};
if src_dir.join("aeropkg.applied-build").exists() {
let src_build = fs::read_to_string(src_dir.join("aeropkg.applied-build")).unwrap_or("".to_string());
if build_script == src_build {
return Ok(())
} else {
println!("build:\n{}\nend build", build_script);
println!("src build:\n{}\nend src build", src_build);
fs::remove_dir_all(src_dir).unwrap();
download(&pkgname, &pkg_md_path)?;
patch(&pkgname, &src_dir, &pkg_md_path)?;
}
}
let output = Command::new("zsh")
.arg("-c")
.arg(&build_script)
@ -346,8 +368,8 @@ fn build(
let output = output.unwrap();
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
eprintln!("Script failed with error: {}", stderr);
return Err(false);
eprintln!("Script failed with error:\n{}", stderr);
std::process::exit(1);
}
let dest_dir = PathBuf::from("/pkg").join(repo).join(pkgname);
@ -357,11 +379,14 @@ fn build(
}
let dest_path = dest_dir.join("build-script.md");
if let Err(e) = fs::copy(pkg_md_path, &dest_path) {
fs::remove_file(&dest_path).expect("");
if let Err(e) = fs::hard_link(pkg_md_path, &dest_path) {
eprintln!("Failed to copy build script to destination: {}", e);
return Err(false);
}
fs::write(src_dir.join("aeropkg.build-script"), &build_script).unwrap();
Ok(())
}
@ -395,3 +420,14 @@ fn config(
Ok(())
}
fn hook(repo: &String, pkgname: &String) {
let pkg_dir = PathBuf::from("/pkg").join(&repo).join(&pkgname);
let lib_dir = &pkg_dir.join("lib");
let lib64_dir = &pkg_dir.join("lib64");
let lib32_dir = &pkg_dir.join("lib32");
crate::utils::mv::mv(&lib64_dir, &lib_dir).unwrap();
crate::utils::mv::mv(&lib32_dir, &lib_dir).unwrap();
fs::remove_dir_all(&lib64_dir).unwrap();
fs::remove_dir_all(&lib32_dir).unwrap();
}