diff --git a/crates/librqbit/src/torrent_state/initializing.rs b/crates/librqbit/src/torrent_state/initializing.rs index 2d55189..d4c0026 100644 --- a/crates/librqbit/src/torrent_state/initializing.rs +++ b/crates/librqbit/src/torrent_state/initializing.rs @@ -16,10 +16,6 @@ use crate::{ use super::{paused::TorrentStatePaused, ManagedTorrentInfo}; -fn ensure_file_length(file: &File, length: u64) -> anyhow::Result<()> { - Ok(file.set_len(length)?) -} - pub struct TorrentStateInitializing { pub(crate) meta: Arc, pub(crate) only_files: Option>, @@ -107,7 +103,7 @@ impl TorrentStateInitializing { .unwrap_or(true) { let now = Instant::now(); - if let Err(err) = ensure_file_length(&file.file.lock(), file.len) { + if let Err(err) = file.file.lock().set_len(file.len) { warn!( "Error setting length for file {:?} to {}: {:#?}", file.filename, file.len, err diff --git a/crates/librqbit/src/torrent_state/streaming.rs b/crates/librqbit/src/torrent_state/streaming.rs index efd4818..bff03b5 100644 --- a/crates/librqbit/src/torrent_state/streaming.rs +++ b/crates/librqbit/src/torrent_state/streaming.rs @@ -343,8 +343,13 @@ impl ManagedTorrent { torrent: self, }; if s.torrent.maybe_reconnect_needed_peers_for_file(file_id) { - s.torrent - .with_opened_file(file_id, |fd| fd.reopen(false))??; + s.torrent.with_opened_file(file_id, |fd| { + fd.reopen(false)?; + fd.file + .lock() + .set_len(fd.len) + .context("error setting file length") + })??; } streams.streams.insert( s.stream_id,