From 8c0898d601b9c75d543bce286451fc97e262852a Mon Sep 17 00:00:00 2001 From: Arthur Beck Date: Mon, 10 Mar 2025 21:34:23 -0500 Subject: [PATCH] more fixes, should be fully functional --- src/lib/lib.rs | 39 ++++++++++++++++++++++++++++----------- src/main.rs | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 56 insertions(+), 19 deletions(-) diff --git a/src/lib/lib.rs b/src/lib/lib.rs index 1e9b387..5cb3947 100644 --- a/src/lib/lib.rs +++ b/src/lib/lib.rs @@ -11,8 +11,8 @@ use std::{ ffi::OsString, io::{Read, Write}, + os::unix::fs::PermissionsExt, path::PathBuf, - os::unix::fs::PermissionsExt }; use base64::Engine; @@ -398,7 +398,7 @@ pub fn populate_index(mirror: Mirror, repo: RepoDescriptor) -> std::io::Result

= vec![]; for line in packages { + if line.is_empty() { + continue; + } let segments = line.split_once(": ").unwrap(); let prefix = segments.0; let suffix = segments.1; @@ -560,7 +563,12 @@ pub fn locate_package( package += &char.to_string(); } - if read_desc(package.clone(), descriptor.clone())?.name != package_name { + let desc = read_desc(package.clone(), descriptor.clone()); + if desc.is_err() { + continue; + } + + if desc?.name != package_name { continue; } @@ -898,8 +906,6 @@ pub fn receive_package( package: String, system: bool, ) -> std::io::Result { - print!("Attempting to recieve package {}...", package); - let path = index_directory()? .join(repo.format()) .join(&package) @@ -945,8 +951,6 @@ pub fn receive_package( } } - std::fs::create_dir_all(&dir)?; - let sig_data = reqwest::blocking::get(sig_url) .unwrap() .bytes() @@ -992,8 +996,8 @@ pub fn receive_package( let tar = ruzstd::decoding::StreamingDecoder::new(&mut reader).unwrap(); let mut archive = tar::Archive::new(tar); - std::fs::remove_dir_all(&dir)?; - std::fs::create_dir(&dir)?; + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir)?; archive.set_overwrite(true); archive.set_preserve_ownerships(false); archive.set_preserve_mtime(true); @@ -1008,8 +1012,6 @@ pub fn receive_package( packages.write_fmt(format_args!("{}-{}\n", desc_hash, package))?; drop(packages); - println!(" Success."); - Ok(dir) } @@ -1022,12 +1024,14 @@ pub fn recieve_package_and_dependencies( ) -> std::io::Result> { let mut out: Vec = vec![]; + print!("[STAT] Downloading package {}...", package); out.push(receive_package( mirror.clone(), repo.clone(), package.clone(), system, )?); + print!(" Done.\n[STAT] Parsing desc..."); let path = index_directory()? .join(repo.clone().format()) @@ -1044,13 +1048,26 @@ pub fn recieve_package_and_dependencies( let desc = read_desc(package.clone(), repo.clone())?; + println!(" Done."); + for package in desc.depends { + print!("[STAT] Downloading package {}...", package); + + let package = package + .split_once("=") + .unwrap_or((&package, "")) + .0 + .to_string(); + let package = package.strip_suffix(">").unwrap_or(&package).to_string(); + let package = package.strip_suffix(".so").unwrap_or(&package).to_string(); + out.push(receive_package( mirror.clone(), repo.clone(), locate_package(package)?[0].0.clone(), system, )?); + println!(" Done."); } Ok(out) } diff --git a/src/main.rs b/src/main.rs index 3aa20fd..aa54ab1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -107,14 +107,20 @@ fn main() -> std::io::Result<()> { for result in results { let mut ok = false; for mirror in &mirrors { - if pacwoman::recieve_package_and_dependencies( + if let Ok(paths) = pacwoman::recieve_package_and_dependencies( mirror.clone(), result.1.clone(), result.0.clone(), !args.user, - ) - .is_ok() - { + ) { + println!( + "[INFO] Successfully retrieved package! Path to it and dependencies are:\n[INFO] {}", + paths + .iter() + .map(|item| item.to_string_lossy()) + .collect::>>() + .join("\n[INFO] ") + ); ok = true; break; } @@ -133,6 +139,8 @@ fn main() -> std::io::Result<()> { if !args.sync.is_empty() { for package in &args.sync { + println!("[INFO] Syncing package {}.", package); + let results = pacwoman::locate_package(package.clone())?; if results.is_empty() { println!(" [ERR] Cannot locate packages for {package}!"); @@ -145,19 +153,31 @@ fn main() -> std::io::Result<()> { for result in results { let mut ok = false; for mirror in &mirrors { - if pacwoman::install_package( + println!( + "[INFO] Attempting to install package {} from {}", + result.0.clone(), + mirror.base() + ); + let pack = pacwoman::install_package( mirror.clone(), result.1.clone(), result.0.clone(), !args.user, - ) - .is_ok() - { + ); + if pack.is_ok() { ok = true; break; + } else { + println!( + "\n[WARN] Error \"{}\" syncing package from mirror {}", + pack.unwrap_err(), + mirror.base() + ); + println!("[INFO] Trying next mirror"); } } if !ok { + println!(" [ERR] Out of mirrors!"); println!(" [ERR] Cannot sync package {}!", result.0); println!(" [TIP] Check the spelling and try syncing repos.");