more fixes, should be fully functional

This commit is contained in:
Arthur Beck 2025-03-10 21:34:23 -05:00
parent 6edfe7cf29
commit 8c0898d601
Signed by: ArthurB
GPG key ID: ACE3D14F5CEF14BF
2 changed files with 56 additions and 19 deletions

View file

@ -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<P
.open(index_directory()?.join("PACKAGES"))?;
packages.write_fmt(format_args!(
"{}-{}-{}: {}",
"{}-{}-{}: {}\n",
digest,
repo.repo(),
repo.arch(),
@ -529,6 +529,9 @@ pub fn locate_package(
let mut out: Vec<(String, RepoDescriptor, PathBuf)> = 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<PathBuf> {
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<Vec<PathBuf>> {
let mut out: Vec<PathBuf> = 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)
}

View file

@ -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::<Vec<std::borrow::Cow<'_, str>>>()
.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.");