From 85ee28196c2e4b6f00fa764ea1cfa98171fe7202 Mon Sep 17 00:00:00 2001 From: PeterDing Date: Thu, 26 Dec 2024 20:19:36 +0800 Subject: [PATCH] Handle error initializing persistent DHT --- src/main.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index df81654..e480825 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ use tracing_subscriber::fmt::time::OffsetTime; use aget::{ app::core::{bt::BtHandler, http::HttpHandler, m3u8::M3u8Handler}, arguments::cmd_args::CmdArgs, - common::tasks::TaskType, + common::{errors::Error, tasks::TaskType}, features::{args::Args, running::Runnable}, }; @@ -57,6 +57,21 @@ fn main() { if let Err(err) = result { tracing::error!("Error: {:?}", err); + + // if error is "error initializing persistent DHT", remove dht.json + if let Error::BitTorrentError(msg) = err { + if msg == "error initializing persistent DHT" { + let output_dir = cmdargs.output(); + let dht_file = output_dir + .join("..") + .join(output_dir.file_name().unwrap().to_string_lossy().to_string() + ".bt.aget") + .join("dht.json"); + if dht_file.exists() { + std::fs::remove_file(dht_file).unwrap(); + } + } + } + // Retry let retrywait = cmdargs.retry_wait(); thread::sleep(Duration::from_secs(retrywait));