diff --git a/crates/librqbit/src/file_ops.rs b/crates/librqbit/src/file_ops.rs index 8bf16c4..23fa8c1 100644 --- a/crates/librqbit/src/file_ops.rs +++ b/crates/librqbit/src/file_ops.rs @@ -181,8 +181,8 @@ impl<'a> FileOps<'a> { let mut piece_remaining_bytes = piece_length as usize; - for (file_idx, file_details) in self.torrent.iter_file_details()?.enumerate() { - let file_len = file_details.len; + for (file_idx, fi) in self.file_infos.iter().enumerate() { + let file_len = fi.len; if absolute_offset > file_len { absolute_offset -= file_len; continue; @@ -208,7 +208,7 @@ impl<'a> FileOps<'a> { .with_context(|| { format!( "error reading {to_read_in_file} bytes, file_id: {file_idx} (\"{:?}\")", - file_details.filename + fi.relative_filename ) })?; @@ -250,7 +250,7 @@ impl<'a> FileOps<'a> { let mut absolute_offset = self.lengths.chunk_absolute_offset(chunk_info); let mut buf = result_buf; - for (file_idx, file_len) in self.torrent.iter_file_lengths()?.enumerate() { + for (file_idx, file_len) in self.file_infos.iter().map(|d| d.len).enumerate() { if absolute_offset > file_len { absolute_offset -= file_len; continue; @@ -296,8 +296,8 @@ impl<'a> FileOps<'a> { let mut buf = data.block.as_ref(); let mut absolute_offset = self.lengths.chunk_absolute_offset(chunk_info); - for (file_idx, file_details) in self.torrent.iter_file_details()?.enumerate() { - let file_len = file_details.len; + for (file_idx, file_info) in self.file_infos.iter().enumerate() { + let file_len = file_info.len; if absolute_offset > file_len { absolute_offset -= file_len; continue; @@ -321,7 +321,7 @@ impl<'a> FileOps<'a> { .with_context(|| { format!( "error writing to file {file_idx} (\"{:?}\")", - file_details.filename + file_info.relative_filename ) })?; buf = &buf[to_write..]; diff --git a/crates/librqbit/src/storage/filesystem/fs.rs b/crates/librqbit/src/storage/filesystem/fs.rs index e2e6076..ef9248d 100644 --- a/crates/librqbit/src/storage/filesystem/fs.rs +++ b/crates/librqbit/src/storage/filesystem/fs.rs @@ -151,13 +151,9 @@ impl TorrentStorage for FilesystemStorage { fn init(&mut self, meta: &ManagedTorrentShared) -> anyhow::Result<()> { let mut files = Vec::::new(); - for file_details in meta.info.iter_file_details_ext(&meta.lengths)? { + for file_details in meta.file_infos.iter() { let mut full_path = self.output_folder.clone(); - let relative_path = file_details - .details - .filename - .to_pathbuf() - .context("error converting file to path")?; + let relative_path = &file_details.relative_filename; full_path.push(relative_path); std::fs::create_dir_all(full_path.parent().context("bug: no parent")?)?;