33 lines
1.2 KiB
Rust
33 lines
1.2 KiB
Rust
|
|
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;
|
||
|
|
|
||
|
|
pub fn patch(
|
||
|
|
repo: &String,
|
||
|
|
pkgname: &String,
|
||
|
|
) -> Result<(), bool> {
|
||
|
|
let src_dir = &crate::commands::get_aeropkg_base().join("src").join(&pkgname);
|
||
|
|
let pkg_md_path = &crate::commands::get_var_path().join(format!("{}/{}.md", &repo, &pkgname));
|
||
|
|
let patch_script = &parser::get_patch_script(pkg_md_path).unwrap_or("".to_string());
|
||
|
|
|
||
|
|
if src_dir.join("aeropkg.applied-patch").exists() {
|
||
|
|
let src_patch = &fs::read_to_string(src_dir.join("aeropkg.applied-patch")).unwrap_or("".to_string());
|
||
|
|
if patch_script == src_patch {
|
||
|
|
return Ok(())
|
||
|
|
} else {
|
||
|
|
fs::remove_dir_all(src_dir).unwrap();
|
||
|
|
download(&repo, &pkgname)?;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if patch_script == "" { return Ok(()) }
|
||
|
|
|
||
|
|
let full_env = get_install_env(repo, pkgname, pkg_md_path, "patch");
|
||
|
|
run_install_script(patch_script, src_dir, &full_env)?;
|
||
|
|
run_install_script_hook(repo, "patch", &full_env)?;
|
||
|
|
fs::write(src_dir.join("aeropkg.applied-patch"), &patch_script).unwrap();
|
||
|
|
|
||
|
|
Ok(())
|
||
|
|
}
|