equal
deleted
inserted
replaced
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 } |