From 0c06601b347bc4a92e9634871887e6684584ceb6 Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Fri, 23 Aug 2024 19:37:31 +0100 Subject: [PATCH] Fix a broken test on Windows --- crates/librqbit/src/session.rs | 14 ++++++------- .../src/torrent_state/initializing.rs | 4 ++-- crates/librqbit/src/upnp_server_adapter.rs | 20 ++++++++++++------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/crates/librqbit/src/session.rs b/crates/librqbit/src/session.rs index 068d8db..9d9ae02 100644 --- a/crates/librqbit/src/session.rs +++ b/crates/librqbit/src/session.rs @@ -208,19 +208,19 @@ fn merge_two_optional_streams( ) -> Option> { match (s1, s2) { (Some(s1), None) => { - debug!("merge_two_optional_streams: using first"); + trace!("merge_two_optional_streams: using first"); Some(Box::pin(s1)) } (None, Some(s2)) => { - debug!("merge_two_optional_streams: using second"); + trace!("merge_two_optional_streams: using second"); Some(Box::pin(s2)) } (Some(s1), Some(s2)) => { - debug!("merge_two_optional_streams: using both"); + trace!("merge_two_optional_streams: using both"); Some(Box::pin(merge_streams(s1, s2))) } (None, None) => { - debug!("merge_two_optional_streams: using none"); + trace!("merge_two_optional_streams: using none"); None } } @@ -909,7 +909,7 @@ impl Session { rx, seen, } => { - debug!(?info, "received result from DHT"); + trace!(?info, "received result from DHT"); let trackers = magnet.trackers.into_iter().unique().collect_vec(); InternalAddResult { info_hash, @@ -924,7 +924,7 @@ impl Session { initial_peers: { let seen = seen.into_iter().collect_vec(); for peer in &seen { - debug!(?peer, "seen") + trace!(?peer, "seen") } seen }, @@ -1045,7 +1045,7 @@ impl Session { info_bytes, } = add_res; - debug!("Torrent info: {:#?}", &info); + trace!("Torrent info: {:#?}", &info); let only_files = compute_only_files( &info, diff --git a/crates/librqbit/src/torrent_state/initializing.rs b/crates/librqbit/src/torrent_state/initializing.rs index 4745abb..89341db 100644 --- a/crates/librqbit/src/torrent_state/initializing.rs +++ b/crates/librqbit/src/torrent_state/initializing.rs @@ -7,7 +7,7 @@ use anyhow::Context; use librqbit_core::lengths::Lengths; use size_format::SizeFormatterBinary as SF; -use tracing::{debug, info, warn}; +use tracing::{info, trace, warn}; use crate::{ api::TorrentIdOrHash, @@ -159,7 +159,7 @@ impl TorrentStateInitializing { fi.relative_filename, fi.len, err ); } else { - debug!( + trace!( "Set length for file {:?} to {} in {:?}", fi.relative_filename, SF::new(fi.len), diff --git a/crates/librqbit/src/upnp_server_adapter.rs b/crates/librqbit/src/upnp_server_adapter.rs index cf188e0..52e6f1f 100644 --- a/crates/librqbit/src/upnp_server_adapter.rs +++ b/crates/librqbit/src/upnp_server_adapter.rs @@ -62,15 +62,21 @@ impl TorrentFileTreeNode { match self.real_torrent_file_id { Some(fid) => { let filename = &torrent.shared().file_infos[fid].relative_filename; - let last_url_bit = filename.to_str().unwrap_or(&self.title); - return ItemOrContainer::Item(Item { + // Torrent path joined with "/" + let last_url_bit = torrent + .shared() + .info + .iter_filenames_and_lengths() + .ok() + .and_then(|mut it| it.nth(fid)) + .and_then(|(fi, _)| fi.to_vec().ok()) + .map(|components| components.join("/")) + .unwrap_or_else(|| self.title.clone()); + ItemOrContainer::Item(Item { id: encoded_id, parent_id: encoded_parent_id, title: self.title.clone(), - mime_type: mime_guess::from_path( - &torrent.shared().file_infos[fid].relative_filename, - ) - .first(), + mime_type: mime_guess::from_path(filename).first(), url: format!( "http://{}:{}/torrents/{}/stream/{}/{}", adapter.hostname, @@ -79,7 +85,7 @@ impl TorrentFileTreeNode { fid, last_url_bit ), - }); + }) } None => ItemOrContainer::Container(Container { id: encoded_id,