Обновление README.md, исходников, пакетки
This commit is contained in:
@ -4,23 +4,30 @@ use std::os::unix::fs::MetadataExt;
|
||||
use glob::Pattern;
|
||||
|
||||
|
||||
pub fn trim_handler(repo: &String, trim_date: i64) {
|
||||
let etc_path = super::get_aeropkg_etc();
|
||||
let cfg_path = etc_path.join("aeropkg.md");
|
||||
let rules = &crate::utils::parser::get_trim_rules(&cfg_path).unwrap();
|
||||
let pkg_dir = &super::get_aeropkg_base().join(repo);
|
||||
|
||||
fn trim(repo: &String, path: &Path, trim_date: i64, rules: &String) -> Result<(), std::io::Error> {
|
||||
let metadata = fs::symlink_metadata(path)?;
|
||||
trim(repo, pkg_dir, trim_date, rules)
|
||||
}
|
||||
|
||||
fn trim(repo: &String, path: &Path, trim_date: i64, rules: &String) {
|
||||
let metadata = fs::symlink_metadata(path).unwrap();
|
||||
|
||||
if metadata.is_dir() {
|
||||
if rules_check(repo, path, rules) {
|
||||
for entry in fs::read_dir(path)? {
|
||||
let entry = entry?;
|
||||
let entry_path = entry.path();
|
||||
trim(repo, &entry_path, trim_date, rules)?;
|
||||
for entry in fs::read_dir(path).unwrap() {
|
||||
let entry_path = &entry.unwrap().path();
|
||||
trim(repo, entry_path, trim_date, rules)
|
||||
}
|
||||
}
|
||||
} else if metadata.is_file() {
|
||||
if rules_check(repo, path, rules) {
|
||||
let atime = metadata.atime();
|
||||
if atime < trim_date {
|
||||
fs::remove_file(path)?;
|
||||
if let Err(e) = fs::remove_file(path) { panic!("Failed to remove file: {}", e) }
|
||||
}
|
||||
}
|
||||
} else if metadata.file_type().is_symlink() {
|
||||
@ -28,26 +35,12 @@ fn trim(repo: &String, path: &Path, trim_date: i64, rules: &String) -> Result<(
|
||||
let symlink_path = if symlink_value.is_relative() { path.parent().unwrap().join(&symlink_value) } else { symlink_value };
|
||||
if !symlink_path.exists() {
|
||||
println!("remove symlink: {} {}", path.display(), symlink_path.display());
|
||||
fs::remove_file(path)?;
|
||||
fs::remove_file(path).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn trim_handler(repo: &String, trim_date: i64) {
|
||||
let etc_path = super::get_etc_path();
|
||||
let cfg_path = etc_path.join("aeropkg.md");
|
||||
|
||||
let rules = crate::utils::parser::get_trim_rules(&cfg_path).unwrap();
|
||||
|
||||
let pkg_dir = super::get_aeropkg_base().join(repo);
|
||||
|
||||
trim(repo, &pkg_dir, trim_date, &rules).unwrap();
|
||||
}
|
||||
|
||||
|
||||
fn rules_check(repo: &String, path: &Path, rules: &String) -> bool {
|
||||
let mut confirm = true;
|
||||
|
||||
@ -60,16 +53,16 @@ fn rules_check(repo: &String, path: &Path, rules: &String) -> bool {
|
||||
}
|
||||
|
||||
let wildcard_string = if rule.starts_with('/') {
|
||||
rule.to_string()
|
||||
&rule.to_string()
|
||||
} else {
|
||||
super::get_aeropkg_base().join(repo).join(rule).to_string_lossy().into_owned()
|
||||
&super::get_aeropkg_base().join(repo).join(rule).to_string_lossy().into_owned()
|
||||
};
|
||||
|
||||
let path_str = path.to_str().unwrap_or("");
|
||||
|
||||
if let Ok(pattern) = Pattern::new(&wildcard_string) {
|
||||
if let Ok(pattern) = Pattern::new(wildcard_string) {
|
||||
if pattern.matches(path_str) {
|
||||
confirm = !invert;
|
||||
confirm = !invert
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user