mirror of
https://github.com/YGGverse/aquatic-crawler.git
synced 2026-04-01 17:45:39 +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`
|
// the destination folder to preload files match `preload_regex`
|
||||||
// * e.g. images for audio albums
|
// * 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()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ impl Preload {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// cleanup temporary files
|
// cleanup temporary files
|
||||||
let t = self.tmp(info_hash)?;
|
let t = self.tmp(info_hash, false)?;
|
||||||
if t.exists() {
|
if t.exists() {
|
||||||
fs::remove_dir_all(t)?
|
fs::remove_dir_all(t)?
|
||||||
}
|
}
|
||||||
|
|
@ -83,7 +83,7 @@ impl Preload {
|
||||||
// Getters
|
// Getters
|
||||||
|
|
||||||
/// * creates new temporary directory if not exists
|
/// * 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) {
|
if !is_info_hash(info_hash) {
|
||||||
bail!("Invalid info-hash `{info_hash}`")
|
bail!("Invalid info-hash `{info_hash}`")
|
||||||
}
|
}
|
||||||
|
|
@ -92,7 +92,7 @@ impl Preload {
|
||||||
if p.is_file() {
|
if p.is_file() {
|
||||||
bail!("Output directory `{}` is file", p.to_string_lossy())
|
bail!("Output directory `{}` is file", p.to_string_lossy())
|
||||||
}
|
}
|
||||||
if !p.exists() {
|
if is_create && !p.exists() {
|
||||||
fs::create_dir(&p)?
|
fs::create_dir(&p)?
|
||||||
}
|
}
|
||||||
Ok(p)
|
Ok(p)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue