diff options
| author | rorka900 <rorka900@gmail.com> | 2026-03-27 18:02:00 +0000 |
|---|---|---|
| committer | rorka900 <rorka900@gmail.com> | 2026-03-27 18:02:00 +0000 |
| commit | 236c78b13a79f290ba8851a4aa0e65ed810e8813 (patch) | |
| tree | 9793dfa6019e872befa0847b74e1812886be3bd1 /src/main.rs | |
| parent | 8eff76834457baab7dc9e2da9e966111c45787c8 (diff) | |
| download | ror-236c78b13a79f290ba8851a4aa0e65ed810e8813.tar.gz ror-236c78b13a79f290ba8851a4aa0e65ed810e8813.zip | |
feat(rootfs): add parallel package downloads and atomic replace command
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index 99b27c8..8daccab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use clap::Parser; use std::path::{Path, PathBuf}; use std::sync::Arc; +use std::thread; use colored::Colorize; mod sync; @@ -74,6 +75,12 @@ struct Args { #[arg(long = "rootfs-arch", default_value = "native")] rootfs_arch: String, + + #[arg(long = "di", value_names = ["DELETE", "INSTALL"], num_args = 2)] + delete_install: Option<Vec<String>>, + + #[arg(long = "lg", alias = "listgroups")] + listgroups: bool, } fn main() { @@ -83,6 +90,7 @@ fn main() { println!("ror {}", env!("CARGO_PKG_VERSION")); return; } + if args.gen_config { let config_path = Path::new("/var/ror/ror.conf"); match config::Config::create_default_config(config_path) { @@ -102,18 +110,114 @@ fn main() { let cfg = Arc::new(config::Config::load()); + if let Some(di_args) = args.delete_install { + let del_pkg = di_args[0].clone(); + let inst_pkg = di_args[1].clone(); + + let db = install::InstalledDB::load(); + + if !db.is_installed(&del_pkg) { + eprintln!("{} Package '{}' is not installed.", "[ror]".red().bold(), del_pkg); + return; + } + + if let Err(e) = delete::check_critical_removal_with_replacement(&del_pkg, &inst_pkg, &db) { + eprintln!("{}", e); + return; + } + + if let Err(e) = delete::check_critical_install(&inst_pkg, &db) { + let already_installed_by_same = db.packages.get(&inst_pkg).is_some(); + if !already_installed_by_same { + let conflict_is_the_deleted = e.contains(&del_pkg); + if !conflict_is_the_deleted { + eprintln!("{}", e); + return; + } + } + } + + let record_files = db.packages + .get(&del_pkg) + .map(|r| r.files.clone()) + .unwrap_or_default(); + + println!( + "{} Replacing '{}' with '{}'...", + "[ror]".blue().bold(), + del_pkg, + inst_pkg + ); + + let del_pkg_for_thread = del_pkg.clone(); + let inst_pkg_for_thread = inst_pkg.clone(); + let cfg_for_thread = Arc::clone(&cfg); + + let del_handle = thread::spawn(move || { + println!("{} [remove] Starting removal of '{}'", ">>>".yellow(), del_pkg_for_thread); + let ok = delete::remove_package_files_only(&del_pkg_for_thread, &record_files); + if ok { + println!("{} [remove] Files removed for '{}'", ">>>".green(), del_pkg_for_thread); + } else { + eprintln!("{} [remove] Errors during removal of '{}'", "[ror]".red().bold(), del_pkg_for_thread); + } + ok + }); + + let inst_handle = thread::spawn(move || { + println!("{} [install] Starting install of '{}'", ">>>".cyan(), inst_pkg_for_thread); + install::install_package_with_result(&inst_pkg_for_thread, &cfg_for_thread) + }); + + let del_ok = del_handle.join().unwrap_or(false); + let inst_result = inst_handle.join().unwrap_or_else(|_| Err("install thread panicked".to_string())); + + let mut db = install::InstalledDB::load(); + + if del_ok { + db.packages.remove(&del_pkg); + println!("{} '{}' removed from database", "[ror]".green(), del_pkg); + } + + match inst_result { + Ok(installed_pkg) => { + db.add_package(installed_pkg); + println!("{} '{}' added to database", "[ror]".green(), inst_pkg); + } + Err(e) => { + eprintln!("{} Failed to install '{}': {}", "[ror]".red().bold(), inst_pkg, e); + } + } + + if let Err(e) = db.save() { + eprintln!("{} Failed to save installed DB: {}", "[ror]".red().bold(), e); + } else { + println!( + "{} Replace operation finished: '{}' -> '{}'", + "[ror]".green().bold(), + del_pkg, + inst_pkg + ); + } + + return; + } + if let Some(pkg) = args.info { info::print_package_info(&pkg); return; } + if args.sync { sync::run_sync(&cfg); return; } + if args.listinstalled { listinstalled::print_installed(); return; } + if args.build_rootfs { let arch = if args.rootfs_arch == "native" { "native" @@ -129,15 +233,29 @@ fn main() { } return; } + if let Some(pkg) = args.delete { delete::remove_package(&pkg); return; } + if let Some(query) = args.search { search::search_packages(&query); return; } + if !args.install.is_empty() { + let db = install::InstalledDB::load(); + for pkg_name in &args.install { + if pkg_name.starts_with('@') { + continue; + } + if let Err(e) = delete::check_critical_install(pkg_name, &db) { + eprintln!("{}", e); + return; + } + } + if args.install[0].starts_with('@') { let group_name = &args.install[0][1..]; match group::load_group(group_name) { @@ -155,6 +273,7 @@ fn main() { } return; } + if args.upgrade { if args.dry_run { let upgradable = update::list_upgradable(); @@ -171,16 +290,19 @@ fn main() { } return; } + if args.repo_list { repo::list_repositories(); return; } + if let Some(repo_args) = args.repo_remove { if let Err(e) = repo::remove_repository(&repo_args) { eprintln!("{} {}", "[ror]".red().bold(), e); } return; } + if let Some(repo_args) = args.repo_add { if repo_args.len() < 2 { eprintln!("{} Usage: --repo-add <name> <url> [mirror]", "[ror]".red().bold()); @@ -194,8 +316,14 @@ fn main() { } return; } + if let Some(pkg) = args.update { update::update_package(&pkg, &cfg, args.dry_run); return; } + + if args.listgroups { + group::list_groups(); + return; + } } |