diff --git a/gix-commitgraph/src/file/init.rs b/gix-commitgraph/src/file/init.rs index 51c2739501f..78e621ab0ae 100644 --- a/gix-commitgraph/src/file/init.rs +++ b/gix-commitgraph/src/file/init.rs @@ -4,9 +4,6 @@ use std::{ path::Path, }; -use bstr::ByteSlice; -use memmap2::Mmap; - use crate::{ file::{ ChunkId, BASE_GRAPHS_LIST_CHUNK_ID, COMMIT_DATA_CHUNK_ID, COMMIT_DATA_ENTRY_SIZE_SANS_HASH, @@ -14,6 +11,7 @@ use crate::{ }, File, }; +use bstr::ByteSlice; /// The error used in [`File::at()`]. #[derive(thiserror::Error, Debug)] @@ -246,7 +244,7 @@ impl TryFrom<&Path> for File { // SAFETY: we have to take the risk of somebody changing the file underneath. Git never writes into the same file. #[allow(unsafe_code)] unsafe { - Mmap::map(&file) + memmap2::MmapOptions::new().map_copy_read_only(&file) } }) .map_err(|e| Error::Io { diff --git a/gix-index/src/file/init.rs b/gix-index/src/file/init.rs index 88dd86af9ac..10c01015fcb 100644 --- a/gix-index/src/file/init.rs +++ b/gix-index/src/file/init.rs @@ -2,8 +2,6 @@ use std::path::{Path, PathBuf}; -use memmap2::Mmap; - use crate::{decode, extension, File, State}; mod error { @@ -64,7 +62,7 @@ impl File { let mut file = std::fs::File::open(&path)?; // SAFETY: we have to take the risk of somebody changing the file underneath. Git never writes into the same file. #[allow(unsafe_code)] - let data = unsafe { Mmap::map(&file)? }; + let data = unsafe { memmap2::MmapOptions::new().map_copy_read_only(&file)? }; if !skip_hash { // Note that even though it's trivial to offload this into a thread, which is worth it for all but the smallest diff --git a/gix-pack/src/lib.rs b/gix-pack/src/lib.rs index b56d1fe983e..ae6f3ffe99c 100755 --- a/gix-pack/src/lib.rs +++ b/gix-pack/src/lib.rs @@ -55,7 +55,7 @@ mod mmap { // SAFETY: we have to take the risk of somebody changing the file underneath. Git never writes into the same file. #[allow(unsafe_code)] unsafe { - memmap2::Mmap::map(&file) + memmap2::MmapOptions::new().map_copy_read_only(&file) } } } diff --git a/gix-pack/tests/pack/index.rs b/gix-pack/tests/pack/index.rs index 1a168b28e79..ddc90cc87c0 100644 --- a/gix-pack/tests/pack/index.rs +++ b/gix-pack/tests/pack/index.rs @@ -148,7 +148,7 @@ mod version { desired_kind, || { let file = std::fs::File::open(fixture_path(data_path))?; - let map = unsafe { memmap2::Mmap::map(&file)? }; + let map = unsafe { memmap2::MmapOptions::map_copy_read_only(&file)? }; Ok((slice_map, map)) }, pack_iter, diff --git a/gix-ref/src/store/packed/buffer.rs b/gix-ref/src/store/packed/buffer.rs index 40fbf88e24a..2283cf9873b 100644 --- a/gix-ref/src/store/packed/buffer.rs +++ b/gix-ref/src/store/packed/buffer.rs @@ -19,7 +19,6 @@ impl AsRef<[u8]> for packed::Backing { pub mod open { use std::path::PathBuf; - use memmap2::Mmap; use winnow::{prelude::*, stream::Offset}; use crate::store_impl::packed; @@ -81,7 +80,7 @@ pub mod open { // SAFETY: we have to take the risk of somebody changing the file underneath. Git never writes into the same file. #[allow(unsafe_code)] unsafe { - Mmap::map(&std::fs::File::open(&path)?)? + memmap2::MmapOptions::new().map_copy_read_only(&std::fs::File::open(&path)?)? }, ) };