mirror of
https://github.com/YGGverse/aquatic-crawler.git
synced 2026-03-31 17:15:35 +00:00
update cleanup function api
This commit is contained in:
parent
8e8b60fe31
commit
279c5217da
2 changed files with 6 additions and 5 deletions
|
|
@ -126,7 +126,7 @@ async fn main() -> Result<()> {
|
|||
.await?;
|
||||
// cleanup irrelevant files (see rqbit#408)
|
||||
if let Some(ref r) = arg.preload_regex {
|
||||
storage.purge_preload_regex(&i, r)?;
|
||||
storage.cleanup(&i, r)?;
|
||||
}
|
||||
// ignore on the next crawl iterations for this session
|
||||
index.insert(mt.info_hash().as_string());
|
||||
|
|
|
|||
|
|
@ -53,16 +53,17 @@ impl Storage {
|
|||
Ok(p.to_string_lossy().to_string())
|
||||
}
|
||||
|
||||
/// Recursively remove all files match `pattern` under `infohash` location
|
||||
pub fn purge_preload_regex(&self, infohash: &str, pattern: &str) -> Result<()> {
|
||||
let r = regex::Regex::new(pattern)?;
|
||||
/// Recursively remove all files under the `infohash` location
|
||||
/// that do not match the `skip_filename_pattern` (see rqbit#408)
|
||||
pub fn cleanup(&self, infohash: &str, skip_filename_pattern: &str) -> Result<()> {
|
||||
let r = regex::Regex::new(skip_filename_pattern)?;
|
||||
for e in walkdir::WalkDir::new(self.output_folder(infohash, false)?)
|
||||
.into_iter()
|
||||
.filter_map(Result::ok)
|
||||
{
|
||||
let p = e.path();
|
||||
if p.is_file() && !r.is_match(p.to_str().unwrap()) {
|
||||
std::fs::remove_file(p)?;
|
||||
fs::remove_file(p)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue