mirror of
https://github.com/YGGverse/aquatic-crawler.git
synced 2026-04-02 10:05:30 +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?;
|
.await?;
|
||||||
// cleanup irrelevant files (see rqbit#408)
|
// cleanup irrelevant files (see rqbit#408)
|
||||||
if let Some(ref r) = arg.preload_regex {
|
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
|
// ignore on the next crawl iterations for this session
|
||||||
index.insert(mt.info_hash().as_string());
|
index.insert(mt.info_hash().as_string());
|
||||||
|
|
|
||||||
|
|
@ -53,16 +53,17 @@ impl Storage {
|
||||||
Ok(p.to_string_lossy().to_string())
|
Ok(p.to_string_lossy().to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Recursively remove all files match `pattern` under `infohash` location
|
/// Recursively remove all files under the `infohash` location
|
||||||
pub fn purge_preload_regex(&self, infohash: &str, pattern: &str) -> Result<()> {
|
/// that do not match the `skip_filename_pattern` (see rqbit#408)
|
||||||
let r = regex::Regex::new(pattern)?;
|
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)?)
|
for e in walkdir::WalkDir::new(self.output_folder(infohash, false)?)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(Result::ok)
|
.filter_map(Result::ok)
|
||||||
{
|
{
|
||||||
let p = e.path();
|
let p = e.path();
|
||||||
if p.is_file() && !r.is_match(p.to_str().unwrap()) {
|
if p.is_file() && !r.is_match(p.to_str().unwrap()) {
|
||||||
std::fs::remove_file(p)?;
|
fs::remove_file(p)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue