2025-11-18 19:46:36 +03:00
|
|
|
use std::fs;
|
|
|
|
|
|
|
|
|
|
use crate::utils::parser::{self, env::get_install_env};
|
|
|
|
|
use crate::utils::shell::{run_install_script,run_install_script_hook};
|
|
|
|
|
use super::download::download;
|
|
|
|
|
|
2026-03-27 13:13:52 +03:00
|
|
|
pub fn patch(repo: &String, pkgname: &String) {
|
2026-07-22 04:29:56 +03:00
|
|
|
let pkgpath = &crate::commands::get_aeropkg_base().join(repo).join(pkgname);
|
|
|
|
|
fs::create_dir_all(&pkgpath).ok();
|
|
|
|
|
let src = &pkgpath.join("src");
|
|
|
|
|
|
2026-03-27 13:13:52 +03:00
|
|
|
let pkg_md_path = &crate::commands::get_aeropkg_var().join(format!("{}/{}.md", repo, pkgname));
|
2025-11-18 19:46:36 +03:00
|
|
|
let patch_script = &parser::get_patch_script(pkg_md_path).unwrap_or("".to_string());
|
2026-07-22 04:29:56 +03:00
|
|
|
if src.join("aeropkg.applied-patch").exists() {
|
|
|
|
|
let src_patch = &fs::read_to_string(src.join("aeropkg.applied-patch")).unwrap_or("".to_string());
|
2026-03-27 13:13:52 +03:00
|
|
|
if patch_script == src_patch { return }
|
|
|
|
|
else if src_patch != "" {
|
2026-07-22 04:29:56 +03:00
|
|
|
fs::remove_dir_all(src).unwrap();
|
2026-03-27 13:13:52 +03:00
|
|
|
download(repo, pkgname)
|
2025-11-18 19:46:36 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let full_env = get_install_env(repo, pkgname, pkg_md_path, "patch");
|
2026-07-22 04:29:56 +03:00
|
|
|
run_install_script(patch_script, src, &full_env);
|
2026-03-27 13:13:52 +03:00
|
|
|
run_install_script_hook(repo, "patch", &full_env);
|
2026-07-22 04:29:56 +03:00
|
|
|
fs::write(src.join("aeropkg.applied-patch"), &patch_script).unwrap()
|
2025-11-18 19:46:36 +03:00
|
|
|
}
|