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 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.")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue