pkg download command and patches

This commit is contained in:
2026-09-10 16:59:11 +03:00
parent c6dcbc1ca5
commit 60cf4a2523
110 changed files with 1588 additions and 332 deletions

View File

@ -0,0 +1,50 @@
use clap::{Arg, ArgMatches, Command};
use crate::commands;
pub fn command() -> Command {
Command::new("download")
.about("Download packages from repositories")
.arg(
Arg::new("packages")
.help("List of packages to download")
.required(true)
.num_args(1..)
.index(1)
)
.arg(
Arg::new("repo")
.short('r')
.long("repo")
.help("Repository name (e.g., gnu, musl). If omitted, determined per-package.")
.required(false),
)
.arg(
Arg::new("force")
.short('d')
.long("delete")
.help("Pass --delete to rsync and force re-download")
.action(clap::ArgAction::SetTrue),
)
.arg(
Arg::new("recursive")
.short('R')
.long("recursive")
.help("Recursively download dependencies")
.action(clap::ArgAction::SetTrue),
)
}
pub fn download(matches: &ArgMatches) {
let packages: Vec<String> = matches
.get_many::<String>("packages")
.unwrap_or_default()
.map(|s| s.to_string())
.collect();
let force = matches.get_flag("force");
let recursive = matches.get_flag("recursive");
let repo = matches.get_one::<String>("repo").map(|s| s.as_str());
commands::download::download_packages(repo, &packages, force, recursive);
}

View File

@ -5,3 +5,4 @@ pub mod enable;
pub mod link;
pub mod run;
pub mod trim;
pub mod download;

View File

@ -85,6 +85,7 @@ fn hardcopy(
}
fs::remove_file(destination).ok();
}
fs::remove_file(destination).ok();
unix::fs::symlink(symlink_value, destination)?
}

View File

@ -35,7 +35,7 @@ fn extract_block(file_path: &Path, start_marker: &str, end_marker: &str) -> io::
if line.trim() == start_marker { block_started = true; continue }
if block_started {
if line.trim() == end_marker { break }
result.push(line.trim().to_string())
result.push(line.to_string())
}
}

View File

@ -3,7 +3,25 @@ use super::*;
pub fn get_repo_addr(repo: &str) -> String {
let file_path = &crate::commands::get_aeropkg_etc().join("aeropkg.md");
let block = extract_block(file_path, "``` cfg *** Repository list and priority ***", "```").expect("Can't parse repo list block");
let block = extract_block(file_path, "``` cfg *** .pkg files sources ***", "```").expect("Can't parse .pkg source block");
for line in block.lines() {
let trimmed_line = line.trim();
if !trimmed_line.is_empty() {
let parts: Vec<&str> = trimmed_line.split_whitespace().collect();
if parts.len() >= 2 && parts[0] == repo {
return parts[1].to_string()
}
}
}
panic!("Repository '{}' not found in the repository list", repo)
}
pub fn get_download_source(repo: &str) -> String {
let file_path = &crate::commands::get_aeropkg_etc().join("aeropkg.md");
let block = extract_block(file_path, "``` cfg *** download sources ***", "```").expect("Can't parse download sources block");
for line in block.lines() {
let trimmed_line = line.trim();
@ -21,7 +39,7 @@ pub fn get_repo_addr(repo: &str) -> String {
pub fn get_repo_list() -> Vec<String> {
let file_path = &crate::commands::get_aeropkg_etc().join("aeropkg.md");
let block = extract_block(file_path, "``` cfg *** Repository list and priority ***", "```").expect("Can't parse repo list block");
let block = extract_block(file_path, "``` cfg *** .pkg files sources ***", "```").expect("Can't parse repo list block");
let mut repo_list = Vec::new();
for line in block.lines() {