more fixes, should be fully functional
This commit is contained in:
parent
6edfe7cf29
commit
8c0898d601
2 changed files with 56 additions and 19 deletions
|
@ -11,8 +11,8 @@
|
||||||
use std::{
|
use std::{
|
||||||
ffi::OsString,
|
ffi::OsString,
|
||||||
io::{Read, Write},
|
io::{Read, Write},
|
||||||
|
os::unix::fs::PermissionsExt,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
os::unix::fs::PermissionsExt
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use base64::Engine;
|
use base64::Engine;
|
||||||
|
@ -398,7 +398,7 @@ pub fn populate_index(mirror: Mirror, repo: RepoDescriptor) -> std::io::Result<P
|
||||||
.open(index_directory()?.join("PACKAGES"))?;
|
.open(index_directory()?.join("PACKAGES"))?;
|
||||||
|
|
||||||
packages.write_fmt(format_args!(
|
packages.write_fmt(format_args!(
|
||||||
"{}-{}-{}: {}",
|
"{}-{}-{}: {}\n",
|
||||||
digest,
|
digest,
|
||||||
repo.repo(),
|
repo.repo(),
|
||||||
repo.arch(),
|
repo.arch(),
|
||||||
|
@ -529,6 +529,9 @@ pub fn locate_package(
|
||||||
let mut out: Vec<(String, RepoDescriptor, PathBuf)> = vec![];
|
let mut out: Vec<(String, RepoDescriptor, PathBuf)> = vec![];
|
||||||
|
|
||||||
for line in packages {
|
for line in packages {
|
||||||
|
if line.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let segments = line.split_once(": ").unwrap();
|
let segments = line.split_once(": ").unwrap();
|
||||||
let prefix = segments.0;
|
let prefix = segments.0;
|
||||||
let suffix = segments.1;
|
let suffix = segments.1;
|
||||||
|
@ -560,7 +563,12 @@ pub fn locate_package(
|
||||||
package += &char.to_string();
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -898,8 +906,6 @@ pub fn receive_package(
|
||||||
package: String,
|
package: String,
|
||||||
system: bool,
|
system: bool,
|
||||||
) -> std::io::Result<PathBuf> {
|
) -> std::io::Result<PathBuf> {
|
||||||
print!("Attempting to recieve package {}...", package);
|
|
||||||
|
|
||||||
let path = index_directory()?
|
let path = index_directory()?
|
||||||
.join(repo.format())
|
.join(repo.format())
|
||||||
.join(&package)
|
.join(&package)
|
||||||
|
@ -945,8 +951,6 @@ pub fn receive_package(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::fs::create_dir_all(&dir)?;
|
|
||||||
|
|
||||||
let sig_data = reqwest::blocking::get(sig_url)
|
let sig_data = reqwest::blocking::get(sig_url)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.bytes()
|
.bytes()
|
||||||
|
@ -992,8 +996,8 @@ pub fn receive_package(
|
||||||
|
|
||||||
let tar = ruzstd::decoding::StreamingDecoder::new(&mut reader).unwrap();
|
let tar = ruzstd::decoding::StreamingDecoder::new(&mut reader).unwrap();
|
||||||
let mut archive = tar::Archive::new(tar);
|
let mut archive = tar::Archive::new(tar);
|
||||||
std::fs::remove_dir_all(&dir)?;
|
let _ = std::fs::remove_dir_all(&dir);
|
||||||
std::fs::create_dir(&dir)?;
|
std::fs::create_dir_all(&dir)?;
|
||||||
archive.set_overwrite(true);
|
archive.set_overwrite(true);
|
||||||
archive.set_preserve_ownerships(false);
|
archive.set_preserve_ownerships(false);
|
||||||
archive.set_preserve_mtime(true);
|
archive.set_preserve_mtime(true);
|
||||||
|
@ -1008,8 +1012,6 @@ pub fn receive_package(
|
||||||
packages.write_fmt(format_args!("{}-{}\n", desc_hash, package))?;
|
packages.write_fmt(format_args!("{}-{}\n", desc_hash, package))?;
|
||||||
drop(packages);
|
drop(packages);
|
||||||
|
|
||||||
println!(" Success.");
|
|
||||||
|
|
||||||
Ok(dir)
|
Ok(dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1022,12 +1024,14 @@ pub fn recieve_package_and_dependencies(
|
||||||
) -> std::io::Result<Vec<PathBuf>> {
|
) -> std::io::Result<Vec<PathBuf>> {
|
||||||
let mut out: Vec<PathBuf> = vec![];
|
let mut out: Vec<PathBuf> = vec![];
|
||||||
|
|
||||||
|
print!("[STAT] Downloading package {}...", package);
|
||||||
out.push(receive_package(
|
out.push(receive_package(
|
||||||
mirror.clone(),
|
mirror.clone(),
|
||||||
repo.clone(),
|
repo.clone(),
|
||||||
package.clone(),
|
package.clone(),
|
||||||
system,
|
system,
|
||||||
)?);
|
)?);
|
||||||
|
print!(" Done.\n[STAT] Parsing desc...");
|
||||||
|
|
||||||
let path = index_directory()?
|
let path = index_directory()?
|
||||||
.join(repo.clone().format())
|
.join(repo.clone().format())
|
||||||
|
@ -1044,13 +1048,26 @@ pub fn recieve_package_and_dependencies(
|
||||||
|
|
||||||
let desc = read_desc(package.clone(), repo.clone())?;
|
let desc = read_desc(package.clone(), repo.clone())?;
|
||||||
|
|
||||||
|
println!(" Done.");
|
||||||
|
|
||||||
for package in desc.depends {
|
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(
|
out.push(receive_package(
|
||||||
mirror.clone(),
|
mirror.clone(),
|
||||||
repo.clone(),
|
repo.clone(),
|
||||||
locate_package(package)?[0].0.clone(),
|
locate_package(package)?[0].0.clone(),
|
||||||
system,
|
system,
|
||||||
)?);
|
)?);
|
||||||
|
println!(" Done.");
|
||||||
}
|
}
|
||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
|
36
src/main.rs
36
src/main.rs
|
@ -107,14 +107,20 @@ fn main() -> std::io::Result<()> {
|
||||||
for result in results {
|
for result in results {
|
||||||
let mut ok = false;
|
let mut ok = false;
|
||||||
for mirror in &mirrors {
|
for mirror in &mirrors {
|
||||||
if pacwoman::recieve_package_and_dependencies(
|
if let Ok(paths) = pacwoman::recieve_package_and_dependencies(
|
||||||
mirror.clone(),
|
mirror.clone(),
|
||||||
result.1.clone(),
|
result.1.clone(),
|
||||||
result.0.clone(),
|
result.0.clone(),
|
||||||
!args.user,
|
!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;
|
ok = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -133,6 +139,8 @@ fn main() -> std::io::Result<()> {
|
||||||
|
|
||||||
if !args.sync.is_empty() {
|
if !args.sync.is_empty() {
|
||||||
for package in &args.sync {
|
for package in &args.sync {
|
||||||
|
println!("[INFO] Syncing package {}.", package);
|
||||||
|
|
||||||
let results = pacwoman::locate_package(package.clone())?;
|
let results = pacwoman::locate_package(package.clone())?;
|
||||||
if results.is_empty() {
|
if results.is_empty() {
|
||||||
println!(" [ERR] Cannot locate packages for {package}!");
|
println!(" [ERR] Cannot locate packages for {package}!");
|
||||||
|
@ -145,19 +153,31 @@ fn main() -> std::io::Result<()> {
|
||||||
for result in results {
|
for result in results {
|
||||||
let mut ok = false;
|
let mut ok = false;
|
||||||
for mirror in &mirrors {
|
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(),
|
mirror.clone(),
|
||||||
result.1.clone(),
|
result.1.clone(),
|
||||||
result.0.clone(),
|
result.0.clone(),
|
||||||
!args.user,
|
!args.user,
|
||||||
)
|
);
|
||||||
.is_ok()
|
if pack.is_ok() {
|
||||||
{
|
|
||||||
ok = true;
|
ok = true;
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
println!(
|
||||||
|
"\n[WARN] Error \"{}\" syncing package from mirror {}",
|
||||||
|
pack.unwrap_err(),
|
||||||
|
mirror.base()
|
||||||
|
);
|
||||||
|
println!("[INFO] Trying next mirror");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
|
println!(" [ERR] Out of mirrors!");
|
||||||
println!(" [ERR] Cannot sync package {}!", result.0);
|
println!(" [ERR] Cannot sync package {}!", result.0);
|
||||||
println!(" [TIP] Check the spelling and try syncing repos.");
|
println!(" [TIP] Check the spelling and try syncing repos.");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue