delete v0.1
This commit is contained in:
@ -12,3 +12,7 @@ opt-level = 3
|
|||||||
lto = true
|
lto = true
|
||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
panic = "abort"
|
panic = "abort"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "pkg"
|
||||||
|
path = "src/main.rs"
|
||||||
|
|||||||
21
install.sh
21
install.sh
@ -1,3 +1,22 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo "Ошибка: Укажите путь установки как аргумент."
|
||||||
|
echo "Пример использования: $0 /pkg/gnu/sexpkg/"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
INSTALL_PATH="$1"
|
||||||
|
|
||||||
|
echo "Сборка проекта..."
|
||||||
cargo build --release
|
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
|
||||||
|
|||||||
@ -4,6 +4,7 @@ use std::path::Path;
|
|||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
|
|
||||||
|
|
||||||
use super::get_var_path;
|
use super::get_var_path;
|
||||||
use crate::utils::parser;
|
use crate::utils::parser;
|
||||||
|
|
||||||
@ -78,35 +79,50 @@ pub fn delete_recursive(repo: &str, pkgname: &str) {
|
|||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(_) => {}
|
Err(_) => {}
|
||||||
}
|
}
|
||||||
|
match remove_unused_dirs_and_symlink(&dir_path) {
|
||||||
|
Ok(()) => {}
|
||||||
|
Err(_) => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn remove_unused_files(dir: &Path) -> Result<(), String> {
|
fn remove_unused_files(path: &Path) -> io::Result<()> {
|
||||||
let entries = fs::read_dir(dir)
|
let metadata = fs::symlink_metadata(path)?;
|
||||||
.map_err(|e| format!("Can't read {}: {}", dir.display(), e))?;
|
|
||||||
|
|
||||||
entries.par_bridge().for_each(|entry| {
|
if metadata.file_type().is_file() {
|
||||||
if let Ok(entry) = entry {
|
if get_nlink(path)? == 1 {
|
||||||
let path = entry.path();
|
fs::remove_file(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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} 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) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
} 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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user