@@ -209,7 +209,7 @@ impl Api {
209209 let mut r = TorrentDetailsResponse {
210210 id : Some ( id) ,
211211 info_hash : mgr. shared ( ) . info_hash . as_string ( ) ,
212- name : mgr. shared ( ) . info . name . as_ref ( ) . map ( |n| n . to_string ( ) ) ,
212+ name : mgr. name ( ) ,
213213 output_folder : mgr
214214 . shared ( )
215215 . options
@@ -245,7 +245,8 @@ impl Api {
245245 make_torrent_details (
246246 Some ( handle. id ( ) ) ,
247247 & info_hash,
248- & handle. shared ( ) . info ,
248+ handle. metadata . load ( ) . as_ref ( ) . map ( |r| & r. info ) ,
249+ handle. name ( ) . as_deref ( ) ,
249250 only_files. as_deref ( ) ,
250251 output_folder,
251252 )
@@ -261,8 +262,7 @@ impl Api {
261262 file_idx : usize ,
262263 ) -> Result < & ' static str > {
263264 let handle = self . mgr_handle ( idx) ?;
264- let info = & handle. shared ( ) . info ;
265- torrent_file_mime_type ( info, file_idx)
265+ handle. with_metadata ( |r| torrent_file_mime_type ( & r. info , file_idx) ) ?
266266 }
267267
268268 pub fn api_peer_stats (
@@ -380,7 +380,8 @@ impl Api {
380380 let details = make_torrent_details (
381381 Some ( id) ,
382382 & handle. info_hash ( ) ,
383- & handle. shared ( ) . info ,
383+ handle. metadata . load ( ) . as_ref ( ) . map ( |r| & r. info ) ,
384+ handle. name ( ) . as_deref ( ) ,
384385 handle. only_files ( ) . as_deref ( ) ,
385386 handle
386387 . shared ( )
@@ -416,7 +417,8 @@ impl Api {
416417 details : make_torrent_details (
417418 None ,
418419 & info_hash,
419- & info,
420+ Some ( & info) ,
421+ None ,
420422 only_files. as_deref ( ) ,
421423 output_folder. to_string_lossy ( ) . into_owned ( ) . to_string ( ) ,
422424 )
@@ -426,7 +428,8 @@ impl Api {
426428 let details = make_torrent_details (
427429 Some ( id) ,
428430 & handle. info_hash ( ) ,
429- & handle. shared ( ) . info ,
431+ handle. metadata . load ( ) . as_ref ( ) . map ( |r| & r. info ) ,
432+ handle. name ( ) . as_deref ( ) ,
430433 handle. only_files ( ) . as_deref ( ) ,
431434 handle
432435 . shared ( )
@@ -529,37 +532,43 @@ pub struct ApiAddTorrentResponse {
529532fn make_torrent_details (
530533 id : Option < TorrentId > ,
531534 info_hash : & Id20 ,
532- info : & TorrentMetaV1Info < ByteBufOwned > ,
535+ info : Option < & TorrentMetaV1Info < ByteBufOwned > > ,
536+ name : Option < & str > ,
533537 only_files : Option < & [ usize ] > ,
534538 output_folder : String ,
535539) -> Result < TorrentDetailsResponse > {
536- let files = info
537- . iter_file_details ( )
538- . context ( "error iterating filenames and lengths" ) ?
539- . enumerate ( )
540- . map ( |( idx, d) | {
541- let name = match d. filename . to_string ( ) {
542- Ok ( s) => s,
543- Err ( err) => {
544- warn ! ( "error reading filename: {:?}" , err) ;
545- "<INVALID NAME>" . to_string ( )
540+ let files = match info {
541+ Some ( info) => info
542+ . iter_file_details ( )
543+ . context ( "error iterating filenames and lengths" ) ?
544+ . enumerate ( )
545+ . map ( |( idx, d) | {
546+ let name = match d. filename . to_string ( ) {
547+ Ok ( s) => s,
548+ Err ( err) => {
549+ warn ! ( "error reading filename: {:?}" , err) ;
550+ "<INVALID NAME>" . to_string ( )
551+ }
552+ } ;
553+ let components = d. filename . to_vec ( ) . unwrap_or_default ( ) ;
554+ let included = only_files. map ( |o| o. contains ( & idx) ) . unwrap_or ( true ) ;
555+ TorrentDetailsResponseFile {
556+ name,
557+ components,
558+ length : d. len ,
559+ included,
560+ attributes : d. attrs ( ) ,
546561 }
547- } ;
548- let components = d. filename . to_vec ( ) . unwrap_or_default ( ) ;
549- let included = only_files. map ( |o| o. contains ( & idx) ) . unwrap_or ( true ) ;
550- TorrentDetailsResponseFile {
551- name,
552- components,
553- length : d. len ,
554- included,
555- attributes : d. attrs ( ) ,
556- }
557- } )
558- . collect ( ) ;
562+ } )
563+ . collect ( ) ,
564+ None => Default :: default ( ) ,
565+ } ;
559566 Ok ( TorrentDetailsResponse {
560567 id,
561568 info_hash : info_hash. as_string ( ) ,
562- name : info. name . as_ref ( ) . map ( |b| b. to_string ( ) ) ,
569+ name : name
570+ . map ( |s| s. to_owned ( ) )
571+ . or_else ( || info. and_then ( |i| i. name . as_ref ( ) . map ( |b| b. to_string ( ) ) ) ) ,
563572 files : Some ( files) ,
564573 output_folder,
565574 stats : None ,
0 commit comments