From a70e9bc5377a49d5c69690343343d7b4f802495e Mon Sep 17 00:00:00 2001 From: yggverse Date: Fri, 8 Aug 2025 01:22:23 +0300 Subject: [PATCH] add `is_create` option --- src/main.rs | 2 +- src/preload.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 776c40a..bf65878 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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() }), ), diff --git a/src/preload.rs b/src/preload.rs index c73f779..fc7e7dd 100644 --- a/src/preload.rs +++ b/src/preload.rs @@ -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 { + pub fn tmp(&self, info_hash: &str, is_create: bool) -> Result { 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)