rust/hg-core/src/vfs.rs
branchstable
changeset 50180 be019ac8c1e4
parent 49485 ffd4b1f1c9cb
child 50252 a6b8b1ab9116
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 }