Обновление README.md, исходников, пакетки
This commit is contained in:
@ -5,35 +5,81 @@ use std::process::{Command, Stdio};
|
||||
use crate::utils::parser::{self, env::get_install_env};
|
||||
use crate::utils::shell::run_install_script_hook;
|
||||
|
||||
pub fn download(repo: &String, pkgname: &String) -> Result<(), bool> {
|
||||
let pkg_md_path = &crate::commands::get_var_path().join(format!("{}/{}.md", &repo, &pkgname));
|
||||
if !pkg_md_path.exists() { upload_from_repo(&repo, &pkgname, &pkg_md_path)? }
|
||||
pub fn download(repo: &String, pkgname: &String) {
|
||||
let pkg_md_path = &crate::commands::get_aeropkg_var().join(format!("{}/{}.md", repo, pkgname));
|
||||
if !pkg_md_path.exists() { upload_from_repo(repo, pkgname, pkg_md_path) }
|
||||
|
||||
let full_env = get_install_env(repo, pkgname, pkg_md_path, "download");
|
||||
|
||||
let url = match parser::pkginfo::get_url(pkg_md_path) {
|
||||
Ok(url) => url,
|
||||
Err(e) => {
|
||||
eprintln!("Failed to parse URL: {}", e);
|
||||
return Err(false);
|
||||
panic!("Failed to parse URL: {}", e)
|
||||
}
|
||||
};
|
||||
|
||||
let src = crate::commands::get_aeropkg_base().join("src").join(pkgname);
|
||||
if src.exists() {
|
||||
let src_url = fs::read_to_string(src.join("aeropkg.download-url")).unwrap_or("".to_string());
|
||||
if url == src_url {
|
||||
return Ok(())
|
||||
} else {
|
||||
fs::remove_dir_all(&src).unwrap();
|
||||
if url == src_url { return }
|
||||
else {
|
||||
fs::remove_dir_all(&src).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
if url.ends_with(".git") || url.starts_with("git://") {
|
||||
let git_status = Command::new("git")
|
||||
.arg("clone")
|
||||
.arg(&url)
|
||||
.arg(&src)
|
||||
.status();
|
||||
|
||||
if !url.ends_with(".git") {
|
||||
if git_status.is_err() || !git_status.unwrap().success() {
|
||||
panic!("Failed to clone git repository from URL: {}", url)
|
||||
}
|
||||
}
|
||||
else if url.is_empty() { return }
|
||||
else if url.ends_with(".zip") {
|
||||
if let Err(e) = fs::create_dir_all(&src) {
|
||||
eprintln!("Failed to create directory {}: {}", &src.display(), e);
|
||||
return Err(false);
|
||||
panic!("Failed to create directory {}: {}", &src.display(), e)
|
||||
}
|
||||
|
||||
let zip_path = src.join("archive.zip");
|
||||
let wget_status = Command::new("wget")
|
||||
.arg("-O")
|
||||
.arg(&zip_path)
|
||||
.arg("-q")
|
||||
.arg("--show-progress")
|
||||
.arg(&url)
|
||||
.envs(&full_env)
|
||||
.status();
|
||||
|
||||
if wget_status.is_err() || !wget_status.unwrap().success() {
|
||||
panic!("Failed to download zip archive from URL: {}", url)
|
||||
}
|
||||
|
||||
let output_flag = format!("-o{}", src.display());
|
||||
let sevenz_status = Command::new("7z")
|
||||
.arg("x")
|
||||
.arg(&zip_path)
|
||||
.arg(output_flag)
|
||||
.arg("-y")
|
||||
.arg("-bd")
|
||||
.arg("-bso0")
|
||||
.arg("-bse0")
|
||||
.arg("-bsp0")
|
||||
.envs(&full_env)
|
||||
.status();
|
||||
|
||||
if sevenz_status.is_err() || !sevenz_status.unwrap().success() {
|
||||
panic!("Failed to extract zip archive from URL: {}", url)
|
||||
}
|
||||
|
||||
fs::remove_file(&zip_path).ok();
|
||||
}
|
||||
else {
|
||||
if let Err(e) = fs::create_dir_all(&src) {
|
||||
panic!("Failed to create directory {}: {}", &src.display(), e)
|
||||
}
|
||||
let compress_flag = if url.ends_with(".bz2") {
|
||||
"--bzip2"
|
||||
@ -50,8 +96,7 @@ pub fn download(repo: &String, pkgname: &String) -> Result<(), bool> {
|
||||
} else if url.ends_with(".gz") {
|
||||
"--gzip"
|
||||
} else {
|
||||
eprintln!("Unsupported compression format for URL: {}", url);
|
||||
return Err(false);
|
||||
panic!("Unsupported compression format for URL: {}", url)
|
||||
};
|
||||
|
||||
let wget_output = Command::new("wget")
|
||||
@ -65,10 +110,7 @@ pub fn download(repo: &String, pkgname: &String) -> Result<(), bool> {
|
||||
|
||||
let tar_input = match wget_output {
|
||||
Ok(child) => child.stdout.unwrap(),
|
||||
Err(e) => {
|
||||
eprintln!("Failed to execute wget: {}", e);
|
||||
return Err(false);
|
||||
}
|
||||
Err(e) => { panic!("Failed to execute wget: {}", e) }
|
||||
};
|
||||
|
||||
let tar_status = Command::new("tar")
|
||||
@ -81,8 +123,7 @@ pub fn download(repo: &String, pkgname: &String) -> Result<(), bool> {
|
||||
.status();
|
||||
|
||||
if tar_status.is_err() || !tar_status.unwrap().success() {
|
||||
eprintln!("Failed to extract archive from URL: {}", url);
|
||||
return Err(false);
|
||||
panic!("Failed to extract archive from URL: {}", url)
|
||||
}
|
||||
|
||||
let entries = fs::read_dir(&src).unwrap();
|
||||
@ -100,29 +141,16 @@ pub fn download(repo: &String, pkgname: &String) -> Result<(), bool> {
|
||||
fs::rename(entry.path(), dest).unwrap();
|
||||
}
|
||||
|
||||
fs::remove_dir(single_dir).unwrap();
|
||||
}
|
||||
} else {
|
||||
let git_status = Command::new("git")
|
||||
.arg("clone")
|
||||
.arg(&url)
|
||||
.arg(&src)
|
||||
.status();
|
||||
|
||||
if git_status.is_err() || !git_status.unwrap().success() {
|
||||
eprintln!("Failed to clone git repository from URL: {}", url);
|
||||
return Err(false);
|
||||
fs::remove_dir(single_dir).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
fs::write(src.join("aeropkg.download-url"), &url).unwrap();
|
||||
|
||||
run_install_script_hook(repo, "download", &full_env)?;
|
||||
|
||||
Ok(())
|
||||
run_install_script_hook(repo, "download", &full_env)
|
||||
}
|
||||
|
||||
fn upload_from_repo(repo: &String, pkgname: &String, pkg_md_path: &Path) -> Result<(), bool> {
|
||||
fn upload_from_repo(repo: &String, pkgname: &String, pkg_md_path: &Path) {
|
||||
let repo_addr = parser::repoinfo::get_repo_addr(repo);
|
||||
let rsync_command = format!(
|
||||
"rsync --include='{}.md' --exclude='*' {} {}",
|
||||
@ -137,13 +165,9 @@ fn upload_from_repo(repo: &String, pkgname: &String, pkg_md_path: &Path) -> Resu
|
||||
.expect("Failed to execute rsync");
|
||||
|
||||
if !rsync_output.status.success() {
|
||||
eprintln!("broken repo: {}", repo);
|
||||
return Err(false);
|
||||
panic!("broken repo: {}", repo)
|
||||
}
|
||||
if !pkg_md_path.exists() {
|
||||
eprintln!("not found {} in {} repo", pkgname, repo);
|
||||
return Err(true);
|
||||
panic!("not found {} in {} repo", pkgname, repo)
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user