fix preload clear

This commit is contained in:
yggverse 2025-08-01 21:33:10 +03:00
parent 6119510a23
commit 380fd6476b
2 changed files with 12 additions and 4 deletions

View file

@ -40,7 +40,7 @@ async fn main() -> Result<()> {
} // librqbit impl dependency
let database = Database::init(&config.database)?;
let peers = Peers::init(&config.initial_peer)?;
let mut preload = Preload::init(
let preload = Preload::init(
config.preload,
config.preload_max_filecount,
config.preload_max_filesize,
@ -261,7 +261,7 @@ async fn main() -> Result<()> {
.delete(librqbit::api::TorrentIdOrHash::Id(id), false)
.await?;
// cleanup tmp
preload.clear();
preload.clear()?;
if config.debug {
println!("\t\t\tadd `{i}` to index.")
}

View file

@ -24,8 +24,16 @@ impl Preload {
})
}
pub fn clear(&mut self) {
self.directory.clear()
pub fn clear(&self) -> Result<()> {
for entry in fs::read_dir(&self.directory)? {
let e = entry?;
if e.file_type()?.is_dir() {
fs::remove_dir_all(e)?;
} else {
fs::remove_file(e)?;
}
}
Ok(())
}
pub fn directory(&self) -> &PathBuf {