From 108ad744640172ed7332de599333b1652f4beb0f Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Mon, 6 May 2024 23:02:10 +0300 Subject: [PATCH] Fix a bug in experimental mmap storage --- .zed/settings.json | 18 ++++++++++++++++++ crates/librqbit/src/storage/filesystem/mmap.rs | 8 +++++--- 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 .zed/settings.json diff --git a/.zed/settings.json b/.zed/settings.json new file mode 100644 index 0000000..8496672 --- /dev/null +++ b/.zed/settings.json @@ -0,0 +1,18 @@ +// Folder-specific settings +// +// For a full list of overridable settings, and general information on folder-specific settings, +// see the documentation: https://zed.dev/docs/configuring-zed#folder-specific-settings +{ + "lsp": { + "rust-analyzer": { + "initialization_options": { + "check": { + "command": "clippy" // rust-analyzer.check.command (default: "check") + }, + "cargo": { + "features": ["librqbit/storage_middleware"] + } + } + } + } +} diff --git a/crates/librqbit/src/storage/filesystem/mmap.rs b/crates/librqbit/src/storage/filesystem/mmap.rs index e5ef44a..87e4157 100644 --- a/crates/librqbit/src/storage/filesystem/mmap.rs +++ b/crates/librqbit/src/storage/filesystem/mmap.rs @@ -25,9 +25,11 @@ impl StorageFactory for MmapFilesystemStorageFactory { fn init_storage(&self, meta: &ManagedTorrentInfo) -> anyhow::Result { let fs_storage = FilesystemStorageFactory::default().init_storage(meta)?; let mut mmaps = Vec::new(); - for file in fs_storage.opened_files.iter() { - let mmap = unsafe { MmapOptions::new().map_mut(&*file.file.read()) } - .context("error mapping file")?; + for (idx, file) in fs_storage.opened_files.iter().enumerate() { + let fg = file.file.write(); + fg.set_len(meta.file_infos[idx].len) + .context("mmap storage: error setting length")?; + let mmap = unsafe { MmapOptions::new().map_mut(&*fg) }.context("error mapping file")?; mmaps.push(RwLock::new(mmap)); }