handle AddTorrentResponse::AlreadyManaged case

This commit is contained in:
yggverse 2025-08-10 15:03:54 +03:00
parent c74a420f1d
commit 99d2fe55e1

View file

@ -134,7 +134,6 @@ async fn main() -> Result<()> {
.await .await
{ {
Ok(r) => match r { Ok(r) => match r {
// on `preload_regex` case only
Ok(AddTorrentResponse::Added(id, mt)) => { Ok(AddTorrentResponse::Added(id, mt)) => {
let mut keep_files = HashSet::with_capacity( let mut keep_files = HashSet::with_capacity(
config.preload_max_filecount.unwrap_or_default(), config.preload_max_filecount.unwrap_or_default(),
@ -192,9 +191,11 @@ async fn main() -> Result<()> {
log::debug!( log::debug!(
"skip awaiting the completion of preload `{i}` data (`{e}`)" "skip awaiting the completion of preload `{i}` data (`{e}`)"
); );
session if !config.enable_upload {
.delete(librqbit::api::TorrentIdOrHash::Id(id), false) session
.await?; // managed torrent is not managed in this queue anymore .delete(librqbit::api::TorrentIdOrHash::Id(id), false)
.await?;
}
continue; continue;
} }
log::debug!("torrent `{i}` preload completed."); log::debug!("torrent `{i}` preload completed.");
@ -205,7 +206,6 @@ async fn main() -> Result<()> {
keep_files.len() keep_files.len()
); );
preload.commit(&i, bytes, Some(keep_files))?; preload.commit(&i, bytes, Some(keep_files))?;
// remove torrent from the session as indexed
if !config.enable_upload { if !config.enable_upload {
session session
.delete(librqbit::api::TorrentIdOrHash::Id(id), false) .delete(librqbit::api::TorrentIdOrHash::Id(id), false)
@ -213,7 +213,14 @@ async fn main() -> Result<()> {
} }
log::debug!("torrent `{i}` resolved.") log::debug!("torrent `{i}` resolved.")
} }
Ok(_) => panic!(), Ok(AddTorrentResponse::AlreadyManaged(..)) => {
if config.enable_upload {
log::debug!("keep sharing the existing torrent data for `{i}`.")
} else {
panic!("torrent `{i}` was not removed properly!")
}
}
Ok(_) => panic!("list only mode is not expected by the implementation!"),
Err(e) => log::debug!("failed to resolve torrent `{i}`: `{e}`."), Err(e) => log::debug!("failed to resolve torrent `{i}`: `{e}`."),
}, },
Err(e) => log::debug!( Err(e) => log::debug!(
@ -236,7 +243,7 @@ async fn main() -> Result<()> {
} }
} }
/// Build magnet URI /// Build magnet URI (`librqbit` impl dependency)
fn magnet(info_hash: &str, trackers: Option<&Vec<Url>>) -> String { fn magnet(info_hash: &str, trackers: Option<&Vec<Url>>) -> String {
let mut m = format!("magnet:?xt=urn:btih:{info_hash}"); let mut m = format!("magnet:?xt=urn:btih:{info_hash}");
if let Some(t) = trackers { if let Some(t) = trackers {