updated build-script format
This commit is contained in:
@ -1,48 +1,21 @@
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
use rayon::prelude::*;
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
|
||||
use super::get_var_path;
|
||||
use std::path::{Path,PathBuf};
|
||||
use crate::utils::parser;
|
||||
|
||||
pub fn delete(repo: &str, pkgname: &str) {
|
||||
let base_dir = Path::new("/pkg").join(repo);
|
||||
let pkg_dir = base_dir.join(pkgname);
|
||||
|
||||
if pkg_dir.exists() {
|
||||
match fs::remove_dir_all(&pkg_dir) {
|
||||
Ok(()) => { println!("removed: {}", pkg_dir.display()) }
|
||||
Err(e) => { eprintln!("Can't remove {}: {}", pkg_dir.display(), e)}
|
||||
}
|
||||
|
||||
} else {
|
||||
eprintln!("{} not installed in {}", pkgname, repo)
|
||||
}
|
||||
|
||||
let subdirs = ["bin", "lib", "libexec", "include", "share"];
|
||||
for subdir in &subdirs {
|
||||
let dir_path = base_dir.join(subdir);
|
||||
if dir_path.exists() {
|
||||
match remove_unused_files(&dir_path) {
|
||||
Ok(()) => {}
|
||||
Err(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn delete(repo: &String, pkgname: &String) {
|
||||
super::disable::disable(&repo, &pkgname).unwrap();
|
||||
fs::remove_dir_all(PathBuf::from("/pkg").join(&repo).join(&pkgname)).unwrap();
|
||||
}
|
||||
|
||||
|
||||
pub fn delete_recursive(repo: &str, pkgname: &str) {
|
||||
let base_dir = Path::new("/pkg").join(repo);
|
||||
let pkg_dir = base_dir.join(pkgname);
|
||||
pub fn delete_recursive(repo: &String, pkgname: &String) {
|
||||
let pkg_dir = Path::new("/pkg").join(repo).join(pkgname);
|
||||
|
||||
if pkg_dir.exists() {
|
||||
let var_path = get_var_path();
|
||||
let var_path = super::get_var_path();
|
||||
let pkg_md_path = var_path.join(format!("{}/{}.md", repo, pkgname));
|
||||
|
||||
match parser::get_deps(&pkg_md_path) {
|
||||
match parser::get_build_deps(&pkg_md_path) {
|
||||
Ok(deps) => {
|
||||
for dependency in deps.lines() {
|
||||
let dependency = dependency.trim();
|
||||
@ -61,72 +34,9 @@ pub fn delete_recursive(repo: &str, pkgname: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
match fs::remove_dir_all(&pkg_dir) {
|
||||
Ok(()) => { println!("removed: {}", pkg_dir.display()) }
|
||||
Err(e) => { eprintln!("Can't remove {}: {}", pkg_dir.display(), e)}
|
||||
}
|
||||
fs::remove_dir_all(&pkg_dir).unwrap();
|
||||
|
||||
} else {
|
||||
eprintln!("{} not installed in {}", pkgname, repo)
|
||||
}
|
||||
|
||||
let subdirs = ["lib", "include", "bin"];
|
||||
for subdir in &subdirs {
|
||||
let dir_path = base_dir.join(subdir);
|
||||
if dir_path.exists() {
|
||||
match remove_unused_files(&dir_path) {
|
||||
Ok(()) => {}
|
||||
Err(_) => {}
|
||||
}
|
||||
match remove_unused_dirs_and_symlink(&dir_path) {
|
||||
Ok(()) => {}
|
||||
Err(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn remove_unused_files(path: &Path) -> io::Result<()> {
|
||||
let metadata = fs::symlink_metadata(path)?;
|
||||
|
||||
if metadata.file_type().is_file() {
|
||||
if get_nlink(path)? == 1 {
|
||||
fs::remove_file(path)?
|
||||
}
|
||||
} else if metadata.file_type().is_dir() {
|
||||
let entries: Vec<_> = fs::read_dir(path)?.collect::<io::Result<Vec<_>>>()?;
|
||||
entries.par_iter().try_for_each(|entry| {
|
||||
remove_unused_files(&entry.path())
|
||||
})?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn remove_unused_dirs_and_symlink(path: &Path) -> io::Result<()> {
|
||||
let metadata = fs::symlink_metadata(path)?;
|
||||
|
||||
if metadata.file_type().is_dir() {
|
||||
let entries: Vec<_> = fs::read_dir(path)?.collect::<io::Result<Vec<_>>>()?;
|
||||
entries.par_iter().try_for_each(|entry| {
|
||||
remove_unused_dirs_and_symlink(&entry.path())
|
||||
})?;
|
||||
|
||||
if fs::read_dir(path)?.next().is_none() {
|
||||
fs::remove_dir(path)?
|
||||
}
|
||||
|
||||
} else if metadata.file_type().is_symlink() {
|
||||
if let Err(_) = fs::metadata(path) {
|
||||
fs::remove_file(path)?
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
fn get_nlink(path: &Path) -> io::Result<u64> {
|
||||
Ok(fs::metadata(path)?.nlink())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user