delete v0.1

This commit is contained in:
2025-06-04 20:33:53 +03:00
parent 51ffa435fb
commit b8fcbe2909
3 changed files with 62 additions and 23 deletions

View File

@ -12,3 +12,7 @@ opt-level = 3
lto = true
codegen-units = 1
panic = "abort"
[[bin]]
name = "pkg"
path = "src/main.rs"

View File

@ -1,3 +1,22 @@
#!/bin/sh
if [ -z "$1" ]; then
echo "Ошибка: Укажите путь установки как аргумент."
echo "Пример использования: $0 /pkg/gnu/sexpkg/"
exit 1
fi
INSTALL_PATH="$1"
echo "Сборка проекта..."
cargo build --release
cargo install --path . --root /pkg/gnu/sexpkg/
echo "Установка в '$INSTALL_PATH'..."
cargo install --path . --root "$INSTALL_PATH"
if [ $? -eq 0 ]; then
echo "Проект успешно установлен в '$INSTALL_PATH'."
else
echo "Ошибка при установке."
exit 1
fi

View File

@ -4,6 +4,7 @@ use std::path::Path;
use rayon::prelude::*;
use std::os::unix::fs::MetadataExt;
use super::get_var_path;
use crate::utils::parser;
@ -78,35 +79,50 @@ pub fn delete_recursive(repo: &str, pkgname: &str) {
Ok(()) => {}
Err(_) => {}
}
match remove_unused_dirs_and_symlink(&dir_path) {
Ok(()) => {}
Err(_) => {}
}
}
}
}
fn remove_unused_files(dir: &Path) -> Result<(), String> {
let entries = fs::read_dir(dir)
.map_err(|e| format!("Can't read {}: {}", dir.display(), e))?;
fn remove_unused_files(path: &Path) -> io::Result<()> {
let metadata = fs::symlink_metadata(path)?;
entries.par_bridge().for_each(|entry| {
if let Ok(entry) = entry {
let path = entry.path();
if path.is_file() {
if let Ok(nlink) = get_nlink(&path) {
if nlink == 1 {
if let Err(e) = fs::remove_file(&path) {
eprintln!("Can't remove {}: {}", path.display(), e)
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)?
}
}
}
} else if path.is_dir() {
if let Err(e) = remove_unused_files(&path) { eprintln!("Error processing directory {}: {}", path.display(), e) }
} else if path.is_symlink() {
if fs::read_link(&path).is_err() {
if let Err(e) = fs::remove_file(&path) { eprintln!("Can't remove symlink {}: {}", path.display(), e) }
}
}
}
});
Ok(())
}