@@ -125,20 +125,10 @@ pub struct DecodedTorrent {
125125
126126impl DecodedTorrent {
127127 pub fn files ( & self ) -> Result < Vec < TorrentContent > , TorrentFileError > {
128- if self . info . files . is_none ( ) {
129- if self . info . file_tree . is_none ( ) {
130- // V1 torrent with single file
131- Ok ( vec ! [ TorrentContent {
132- path: PathBuf :: from( & self . info. name) ,
133- size: self . info. length. unwrap( ) ,
134- } ] )
135- } else {
136- todo ! ( "v2 torrent files" ) ;
137- }
138- } else {
128+ if let Some ( info_files) = & self . info . files {
139129 // V1 torrent with multiple files
140130 let mut files: Vec < TorrentContent > = vec ! [ ] ;
141- for file in self . info . files . as_ref ( ) . unwrap ( ) {
131+ for file in info_files {
142132 // TODO: error
143133 let f: UnsafeV1FileContent = bt_bencode:: from_value ( file. clone ( ) ) . unwrap ( ) ;
144134 if let Some ( parsed_file) = f. to_torrent_content ( ) ? {
@@ -148,8 +138,18 @@ impl DecodedTorrent {
148138
149139 // Sort files by alphabetical order
150140 files. sort ( ) ;
151- Ok ( files)
141+ return Ok ( files) ;
142+ }
143+
144+ if let Some ( _info_file_tree) = & self . info . file_tree {
145+ todo ! ( "v2 torrent files" ) ;
152146 }
147+
148+ // V1 torrent with single file
149+ Ok ( vec ! [ TorrentContent {
150+ path: PathBuf :: from( & self . info. name) ,
151+ size: self . info. length. unwrap( ) ,
152+ } ] )
153153 }
154154}
155155
0 commit comments