mirror of
https://github.com/YGGverse/aquatic-crawler.git
synced 2026-03-31 17:15:35 +00:00
add is_create option
This commit is contained in:
parent
9a6e6dbb0c
commit
a70e9bc537
2 changed files with 4 additions and 4 deletions
|
|
@ -118,7 +118,7 @@ async fn main() -> Result<()> {
|
|||
)),
|
||||
// the destination folder to preload files match `preload_regex`
|
||||
// * e.g. images for audio albums
|
||||
output_folder: preload.tmp(&i)?.to_str().map(|s| s.to_string()),
|
||||
output_folder: preload.tmp(&i, true)?.to_str().map(|s| s.to_string()),
|
||||
..Default::default()
|
||||
}),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ impl Preload {
|
|||
}
|
||||
}
|
||||
// cleanup temporary files
|
||||
let t = self.tmp(info_hash)?;
|
||||
let t = self.tmp(info_hash, false)?;
|
||||
if t.exists() {
|
||||
fs::remove_dir_all(t)?
|
||||
}
|
||||
|
|
@ -83,7 +83,7 @@ impl Preload {
|
|||
// Getters
|
||||
|
||||
/// * creates new temporary directory if not exists
|
||||
pub fn tmp(&self, info_hash: &str) -> Result<PathBuf> {
|
||||
pub fn tmp(&self, info_hash: &str, is_create: bool) -> Result<PathBuf> {
|
||||
if !is_info_hash(info_hash) {
|
||||
bail!("Invalid info-hash `{info_hash}`")
|
||||
}
|
||||
|
|
@ -92,7 +92,7 @@ impl Preload {
|
|||
if p.is_file() {
|
||||
bail!("Output directory `{}` is file", p.to_string_lossy())
|
||||
}
|
||||
if !p.exists() {
|
||||
if is_create && !p.exists() {
|
||||
fs::create_dir(&p)?
|
||||
}
|
||||
Ok(p)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue