upd and patches
This commit is contained in:
@ -6,9 +6,7 @@ pub fn disable(repo: &String, pkgname: &String) {
|
||||
let source = &crate::commands::get_aeropkg_base().join(repo).join(pkgname);
|
||||
if source.join("disabled").exists() { return };
|
||||
|
||||
let destination = &source.parent()
|
||||
.ok_or("Failed to get parent directory for path").unwrap()
|
||||
.to_path_buf();
|
||||
let destination = &crate::commands::get_aeropkg_base().join(repo);
|
||||
|
||||
let dirs_to_copy = vec![
|
||||
("bin"),
|
||||
|
||||
@ -5,9 +5,7 @@ pub fn link(repo: &String, pkgname: &String) {
|
||||
let source = crate::commands::get_aeropkg_base().join(repo).join(pkgname);
|
||||
if source.join("disabled").exists() { println!("Disabled package, no linking: {}\nUse `pkg enable {}` to link", pkgname, pkgname); return }
|
||||
|
||||
let destination = source.parent()
|
||||
.ok_or("Failed to get parent directory for path").unwrap()
|
||||
.to_path_buf();
|
||||
let destination = &crate::commands::get_aeropkg_base().join(repo);
|
||||
|
||||
let dirs_to_copy = vec![
|
||||
("bin"),
|
||||
|
||||
@ -8,7 +8,10 @@ use super::patch::patch;
|
||||
|
||||
|
||||
pub fn build(repo: &String, pkgname: &String) {
|
||||
let src_dir = &crate::commands::get_aeropkg_base().join("src").join(pkgname);
|
||||
let pkgpath = &crate::commands::get_aeropkg_base().join(repo).join(pkgname);
|
||||
fs::create_dir_all(&pkgpath).ok();
|
||||
let src = &pkgpath.join("src");
|
||||
|
||||
let pkg_md_path = &crate::commands::get_aeropkg_var().join(format!("{}/{}.md", repo, pkgname));
|
||||
let builded_pkg_md_path = &crate::commands::get_aeropkg_base().join(repo).join(pkgname).join("build-script.md");
|
||||
|
||||
@ -28,19 +31,19 @@ pub fn build(repo: &String, pkgname: &String) {
|
||||
if build_script == builded_script { return }
|
||||
}
|
||||
|
||||
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 src.join("aeropkg.applied-build").exists() {
|
||||
let src_build = fs::read_to_string(src.join("aeropkg.applied-build")).unwrap_or("".to_string());
|
||||
if build_script == src_build {
|
||||
return
|
||||
} else {
|
||||
fs::remove_dir_all(src_dir).unwrap();
|
||||
fs::remove_dir_all(src).unwrap();
|
||||
download(repo, pkgname);
|
||||
patch(repo, pkgname)
|
||||
}
|
||||
}
|
||||
|
||||
let full_env = get_install_env(repo, pkgname, pkg_md_path, "build");
|
||||
run_install_script(&build_script, src_dir, &full_env);
|
||||
run_install_script(&build_script, src, &full_env);
|
||||
run_install_script_hook(repo, "build", &full_env);
|
||||
|
||||
let dest_dir = crate::commands::get_aeropkg_base().join(repo).join(pkgname);
|
||||
@ -48,12 +51,12 @@ pub fn build(repo: &String, pkgname: &String) {
|
||||
let dest_path = &dest_dir.join("build-script.md");
|
||||
fs::remove_file(dest_path).ok();
|
||||
if let Err(e) = fs::hard_link(pkg_md_path, dest_path) { panic!("Failed to copy build script to destination: {}", e) }
|
||||
fs::write(src_dir.join("aeropkg.build-script"), &build_script).unwrap();
|
||||
fs::write(src.join("aeropkg.build-script"), &build_script).unwrap();
|
||||
|
||||
|
||||
let save_source_flag = full_env.get("save_source").map_or(false, |v| v == "true");
|
||||
if !save_source_flag {
|
||||
if let Err(e) = fs::remove_dir_all(&src_dir) { panic!("Failed to remove source directory: {}", e) }
|
||||
if let Err(e) = fs::remove_dir_all(&src) { panic!("Failed to remove source directory: {}", e) }
|
||||
}
|
||||
|
||||
hook(repo, pkgname);
|
||||
|
||||
@ -18,7 +18,10 @@ pub fn download(repo: &String, pkgname: &String) {
|
||||
}
|
||||
};
|
||||
|
||||
let src = crate::commands::get_aeropkg_base().join("src").join(pkgname);
|
||||
let pkgpath = &crate::commands::get_aeropkg_base().join(repo).join(pkgname);
|
||||
fs::create_dir_all(&pkgpath).ok();
|
||||
|
||||
let src = pkgpath.join("src");
|
||||
if src.exists() {
|
||||
let src_url = fs::read_to_string(src.join("aeropkg.download-url")).unwrap_or("".to_string());
|
||||
if url == src_url { return }
|
||||
@ -29,6 +32,7 @@ pub fn download(repo: &String, pkgname: &String) {
|
||||
|
||||
if url.ends_with(".git") || url.starts_with("git://") {
|
||||
let git_status = Command::new("git")
|
||||
.current_dir(&pkgpath)
|
||||
.arg("clone")
|
||||
.arg(&url)
|
||||
.arg(&src)
|
||||
|
||||
@ -5,21 +5,23 @@ use crate::utils::shell::{run_install_script,run_install_script_hook};
|
||||
use super::download::download;
|
||||
|
||||
pub fn patch(repo: &String, pkgname: &String) {
|
||||
let src_dir = &crate::commands::get_aeropkg_base().join("src").join(pkgname);
|
||||
let pkgpath = &crate::commands::get_aeropkg_base().join(repo).join(pkgname);
|
||||
fs::create_dir_all(&pkgpath).ok();
|
||||
let src = &pkgpath.join("src");
|
||||
|
||||
let pkg_md_path = &crate::commands::get_aeropkg_var().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 src.join("aeropkg.applied-patch").exists() {
|
||||
let src_patch = &fs::read_to_string(src.join("aeropkg.applied-patch")).unwrap_or("".to_string());
|
||||
if patch_script == src_patch { return }
|
||||
else if src_patch != "" {
|
||||
fs::remove_dir_all(src_dir).unwrap();
|
||||
fs::remove_dir_all(src).unwrap();
|
||||
download(repo, pkgname)
|
||||
}
|
||||
}
|
||||
|
||||
let full_env = get_install_env(repo, pkgname, pkg_md_path, "patch");
|
||||
run_install_script(patch_script, src_dir, &full_env);
|
||||
run_install_script(patch_script, src, &full_env);
|
||||
run_install_script_hook(repo, "patch", &full_env);
|
||||
fs::write(src_dir.join("aeropkg.applied-patch"), &patch_script).unwrap()
|
||||
fs::write(src.join("aeropkg.applied-patch"), &patch_script).unwrap()
|
||||
}
|
||||
|
||||
@ -15,7 +15,6 @@ fn hardcopy(
|
||||
) -> io::Result<()> {
|
||||
let metadata = fs::symlink_metadata(source)?;
|
||||
|
||||
|
||||
if metadata.file_type().is_file() {
|
||||
match fs::hard_link(source, destination) {
|
||||
Ok(_) => {}
|
||||
@ -39,7 +38,7 @@ fn hardcopy(
|
||||
let conflict_list = find_files_with_location(&destination);
|
||||
|
||||
let count = conflict_list.len();
|
||||
if count == 1 {
|
||||
if count <= 1 {
|
||||
fs::remove_file(destination)?;
|
||||
fs::hard_link(source, destination)?
|
||||
} else if count >= 1 {
|
||||
@ -75,7 +74,17 @@ fn hardcopy(
|
||||
})?
|
||||
} else if metadata.file_type().is_symlink() {
|
||||
let symlink_value = fs::read_link(source)?;
|
||||
if destination.exists() { fs::remove_file(destination)? }
|
||||
|
||||
if let Ok(dest_meta) = fs::symlink_metadata(destination) {
|
||||
if dest_meta.is_symlink() {
|
||||
if let Ok(dest_target) = fs::read_link(destination) {
|
||||
if dest_target == symlink_value {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
fs::remove_file(destination).ok();
|
||||
}
|
||||
unix::fs::symlink(symlink_value, destination)?
|
||||
}
|
||||
|
||||
|
||||
@ -8,8 +8,11 @@ use super::*;
|
||||
|
||||
pub fn get_install_env(repo: &String, pkgname: &String, pkg_md_path: &Path, stage: &str) -> HashMap<String, String> {
|
||||
let mut full_env = HashMap::new();
|
||||
let pkgpath = crate::commands::get_aeropkg_base().join(repo).join(pkgname);
|
||||
|
||||
full_env.insert("repo".to_string(), repo.clone());
|
||||
full_env.insert("pkgname".to_string(), pkgname.clone());
|
||||
full_env.insert("pkgpath".to_string(), pkgpath.to_string_lossy().into_owned());
|
||||
if let Some(global_env) = get_global_env_string().ok() { full_env.extend(global_env) }
|
||||
if let Some(pkg_env) = get_pkg_env(pkg_md_path).ok() { full_env.extend(pkg_env) }
|
||||
if let Some(repo_env) = get_repo_env(repo).ok() { full_env.extend(repo_env) }
|
||||
@ -21,8 +24,11 @@ pub fn get_install_env(repo: &String, pkgname: &String, pkg_md_path: &Path, stag
|
||||
|
||||
pub fn get_custom_env(repo: &String, pkgname: &String, pkg_md_path: &Path) -> HashMap<String, String> {
|
||||
let mut full_env = HashMap::new();
|
||||
let pkgpath = crate::commands::get_aeropkg_base().join(repo).join(pkgname);
|
||||
|
||||
full_env.insert("repo".to_string(), repo.clone());
|
||||
full_env.insert("pkgname".to_string(), pkgname.clone());
|
||||
full_env.insert("pkgpath".to_string(), pkgpath.to_string_lossy().into_owned());
|
||||
if let Some(global_env) = get_global_env_string().ok() { full_env.extend(global_env) }
|
||||
if let Some(pkg_env) = get_pkg_env(pkg_md_path).ok() { full_env.extend(pkg_env) }
|
||||
if let Some(repo_env) = get_repo_env(repo).ok() { full_env.extend(repo_env) }
|
||||
@ -34,6 +40,7 @@ pub fn get_global_env() -> HashMap<String, String> {
|
||||
let mut full_env = HashMap::new();
|
||||
full_env.insert("aeropkg_home".to_string(), crate::commands::get_aeropkg_home().to_string_lossy().into_owned().clone());
|
||||
full_env.insert("aeropkg_base".to_string(), crate::commands::get_aeropkg_base().to_string_lossy().into_owned().clone());
|
||||
full_env.insert("pkgbase".to_string(), crate::commands::get_aeropkg_base().to_string_lossy().into_owned().clone());
|
||||
full_env.insert("aeropkg_etc".to_string(), crate::commands::get_aeropkg_etc().to_string_lossy().into_owned().clone());
|
||||
full_env.insert("aeropkg_var".to_string(), crate::commands::get_aeropkg_var().to_string_lossy().into_owned().clone());
|
||||
if let Some(global_env) = get_global_env_string().ok() { full_env.extend(global_env) }
|
||||
|
||||
Reference in New Issue
Block a user