use info_hash namespace for the tmp data

This commit is contained in:
yggverse 2025-08-02 15:33:07 +03:00
parent 5edaf77a5a
commit 68c734dbb9
2 changed files with 16 additions and 14 deletions

View file

@ -43,7 +43,7 @@ async fn main() -> Result<()> {
)?;
let trackers = Trackers::init(&config.tracker)?;
let session = librqbit::Session::new_with_opts(
preload.directory().clone(),
preload.root(),
SessionOptions {
bind_device_name: config.bind,
listen: None,
@ -128,7 +128,7 @@ 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.directory().to_string_lossy().to_string()),
output_folder: Some(preload.output_folder(&i)?),
..Default::default()
}),
),
@ -247,7 +247,7 @@ async fn main() -> Result<()> {
.delete(librqbit::api::TorrentIdOrHash::Id(id), false)
.await?;
// cleanup tmp dir
preload.clear()?;
preload.clear_output_folder(&i)?;
if config.debug {
println!("\t\t\tadd `{i}` to index.")
}

View file

@ -24,20 +24,22 @@ impl Preload {
})
}
pub fn clear(&self) -> Result<()> {
for e in fs::read_dir(&self.directory)? {
let p = e?.path();
if p.is_dir() {
fs::remove_dir_all(p)?;
} else {
fs::remove_file(p)?;
}
}
pub fn clear_output_folder(&self, info_hash: &str) -> Result<()> {
let mut p = PathBuf::from(&self.directory);
p.push(info_hash);
fs::remove_dir_all(&p)?;
Ok(())
}
pub fn directory(&self) -> &PathBuf {
&self.directory
pub fn output_folder(&self, info_hash: &str) -> Result<String> {
let mut p = PathBuf::from(&self.directory);
p.push(info_hash);
fs::create_dir(&p)?;
Ok(p.to_string_lossy().to_string())
}
pub fn root(&self) -> PathBuf {
self.directory.clone()
}
pub fn bytes(&self, path: &PathBuf) -> Result<Vec<u8>> {