mirror of
https://github.com/YGGverse/btracker.git
synced 2026-03-31 17:15:31 +00:00
use info_hash namespace for the tmp data
This commit is contained in:
parent
5edaf77a5a
commit
68c734dbb9
2 changed files with 16 additions and 14 deletions
|
|
@ -43,7 +43,7 @@ async fn main() -> Result<()> {
|
||||||
)?;
|
)?;
|
||||||
let trackers = Trackers::init(&config.tracker)?;
|
let trackers = Trackers::init(&config.tracker)?;
|
||||||
let session = librqbit::Session::new_with_opts(
|
let session = librqbit::Session::new_with_opts(
|
||||||
preload.directory().clone(),
|
preload.root(),
|
||||||
SessionOptions {
|
SessionOptions {
|
||||||
bind_device_name: config.bind,
|
bind_device_name: config.bind,
|
||||||
listen: None,
|
listen: None,
|
||||||
|
|
@ -128,7 +128,7 @@ async fn main() -> Result<()> {
|
||||||
config.preload_max_filecount.unwrap_or_default(),
|
config.preload_max_filecount.unwrap_or_default(),
|
||||||
)),
|
)),
|
||||||
// the folder to preload temporary files (e.g. images for the audio albums)
|
// 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()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
|
@ -247,7 +247,7 @@ async fn main() -> Result<()> {
|
||||||
.delete(librqbit::api::TorrentIdOrHash::Id(id), false)
|
.delete(librqbit::api::TorrentIdOrHash::Id(id), false)
|
||||||
.await?;
|
.await?;
|
||||||
// cleanup tmp dir
|
// cleanup tmp dir
|
||||||
preload.clear()?;
|
preload.clear_output_folder(&i)?;
|
||||||
if config.debug {
|
if config.debug {
|
||||||
println!("\t\t\tadd `{i}` to index.")
|
println!("\t\t\tadd `{i}` to index.")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,20 +24,22 @@ impl Preload {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear(&self) -> Result<()> {
|
pub fn clear_output_folder(&self, info_hash: &str) -> Result<()> {
|
||||||
for e in fs::read_dir(&self.directory)? {
|
let mut p = PathBuf::from(&self.directory);
|
||||||
let p = e?.path();
|
p.push(info_hash);
|
||||||
if p.is_dir() {
|
fs::remove_dir_all(&p)?;
|
||||||
fs::remove_dir_all(p)?;
|
|
||||||
} else {
|
|
||||||
fs::remove_file(p)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn directory(&self) -> &PathBuf {
|
pub fn output_folder(&self, info_hash: &str) -> Result<String> {
|
||||||
&self.directory
|
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>> {
|
pub fn bytes(&self, path: &PathBuf) -> Result<Vec<u8>> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue