diff --git a/src/lib/lib.rs b/src/lib/lib.rs index 6873d95..6418c82 100644 --- a/src/lib/lib.rs +++ b/src/lib/lib.rs @@ -6,6 +6,7 @@ clippy::missing_panics_doc )] #![feature(str_as_str)] +#![feature(impl_trait_in_bindings)] use std::{ ffi::OsString, @@ -1076,47 +1077,64 @@ pub fn install_package( } } + /// Fuck me. + #[derive(Clone)] + struct VisitDir<'a> { + /// Fuck me. + f: &'a dyn Fn(std::io::Result, VisitDir) -> std::io::Result<()> + } + + let diritem = VisitDir { + f: &|entry: std::io::Result, visit_dir: VisitDir| -> std::io::Result<()> { + let entry = entry?; + + if entry.file_name() == *".BUILDINFO" + || entry.file_name() == *".MTREE" + || entry.file_name() == *".PKGINFO" + { + return Ok(()); + } + + if entry.file_type()?.is_dir() { + std::fs::create_dir_all(out.join(entry.path()))?; + for entry in std::fs::read_dir(path.join(entry.path()))? { + (visit_dir.clone().f)(entry, visit_dir.clone())?; + } + } else { + std::fs::create_dir_all(out.join(entry.path().parent().unwrap()))?; + std::fs::remove_file(out.join(entry.path()))?; + std::os::unix::fs::symlink(path.join(entry.path()), out.join(entry.path()))?; + } + Ok(()) + } + }; + for entry in std::fs::read_dir(&path)? { - println!("entry"); - let entry = entry?; + (diritem.clone().f)(entry, diritem.clone())?; + } - if entry.file_name() == *".BUILDINFO" - || entry.file_name() == *".MTREE" - || entry.file_name() == *".PKGINFO" + if std::fs::exists(out.join(".INSTALL"))? { + std::os::unix::fs::chroot(&out)?; + + if !std::process::Command::new("/usr/bin/bash") + .arg("-c") + .arg("source /.INSTALL && post_install && post_upgrade") + .current_dir(&out) + .spawn()? + .wait()? + .success() { - continue; + println!( + "[WARN] .INSTALL script for package {} failed!", + path.file_name().unwrap().to_string_lossy() + ); } - println!("{}", entry.file_name().to_string_lossy()); - if entry.file_type()?.is_dir() { - std::fs::create_dir_all(out.join(entry.path()))?; - } else { - std::fs::create_dir_all(out.join(entry.path().parent().unwrap()))?; - std::fs::remove_file(out.join(entry.path()))?; - std::os::unix::fs::symlink(path.join(entry.path()), out.join(entry.path()))?; - } + std::os::unix::fs::chroot(".")?; + + std::fs::remove_file(out.join(".INSTALL"))?; } - std::os::unix::fs::chroot(&out)?; - - if !std::process::Command::new("/usr/bin/bash") - .arg("-c") - .arg("source /.INSTALL && post_install && post_upgrade") - .current_dir(&out) - .spawn()? - .wait()? - .success() - { - println!( - "[WARN] .INSTALL script for package {} failed!", - path.file_name().unwrap().to_string_lossy() - ); - } - - std::os::unix::fs::chroot(".")?; - - std::fs::remove_file(out.join(".INSTALL"))?; - let mut packages = std::fs::OpenOptions::new() .create(true) .append(true)