Mercurial > hg
comparison rust/hg-core/src/vfs.rs @ 50180:be019ac8c1e4 stable
dirstate-v2: don't mmap the data file when on NFS
`mmap` on NFS will trigger a SIGBUS when the mmap'ed file is deleted, which
wouldn't work in our case. Also, the performance advantage of using mmap on
NFS is debatable at best.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Mon, 28 Nov 2022 12:33:20 +0100 |
parents | ffd4b1f1c9cb |
children | a6b8b1ab9116 |
comparison
equal
deleted
inserted
replaced
50179:f2e13d8d30e0 | 50180:be019ac8c1e4 |
---|---|
170 } | 170 } |
171 | 171 |
172 pub(crate) fn is_file(path: impl AsRef<Path>) -> Result<bool, HgError> { | 172 pub(crate) fn is_file(path: impl AsRef<Path>) -> Result<bool, HgError> { |
173 Ok(fs_metadata(path)?.map_or(false, |meta| meta.is_file())) | 173 Ok(fs_metadata(path)?.map_or(false, |meta| meta.is_file())) |
174 } | 174 } |
175 | |
176 /// Returns whether the given `path` is on a network file system. | |
177 /// Taken from `cargo`'s codebase. | |
178 #[cfg(target_os = "linux")] | |
179 pub(crate) fn is_on_nfs_mount(path: impl AsRef<Path>) -> bool { | |
180 use std::ffi::CString; | |
181 use std::mem; | |
182 use std::os::unix::prelude::*; | |
183 | |
184 let path = match CString::new(path.as_ref().as_os_str().as_bytes()) { | |
185 Ok(path) => path, | |
186 Err(_) => return false, | |
187 }; | |
188 | |
189 unsafe { | |
190 let mut buf: libc::statfs = mem::zeroed(); | |
191 let r = libc::statfs(path.as_ptr(), &mut buf); | |
192 | |
193 r == 0 && buf.f_type as u32 == libc::NFS_SUPER_MAGIC as u32 | |
194 } | |
195 } |