skip directory create if already exists, return PathBuf, convert to string outside

This commit is contained in:
yggverse 2025-08-02 15:57:41 +03:00
parent 9a64995bf5
commit b4d379c650
2 changed files with 9 additions and 4 deletions

View file

@ -128,7 +128,9 @@ async fn main() -> Result<()> {
config.preload_max_filecount.unwrap_or_default(),
)),
// the folder to preload temporary files (e.g. images for the audio albums)
output_folder: Some(preload.output_folder(&i)?),
output_folder: Some(
preload.output_folder(&i)?.to_string_lossy().to_string(),
),
..Default::default()
}),
),

View file

@ -31,11 +31,14 @@ impl Preload {
Ok(())
}
pub fn output_folder(&self, info_hash: &str) -> Result<String> {
/// * create new directory if not exists
pub fn output_folder(&self, info_hash: &str) -> Result<PathBuf> {
let mut p = PathBuf::from(&self.directory);
p.push(info_hash);
fs::create_dir(&p)?;
Ok(p.to_string_lossy().to_string())
if !p.exists() {
fs::create_dir(&p)?
}
Ok(p)
}
pub fn root(&self) -> PathBuf {