possum/
env.rs

1use cfg_if::cfg_if;
2
3fn emulate_freebsd_from_env() -> bool {
4    use once_cell::sync::OnceCell;
5    static CELL: OnceCell<bool> = OnceCell::new();
6    *CELL.get_or_init(|| {
7        let emulate = !matches!(
8            std::env::var("POSSUM_EMULATE_FREEBSD"),
9            Err(std::env::VarError::NotPresent)
10        );
11        if emulate {
12            super::error!("emulating freebsd");
13        }
14        emulate
15    })
16}
17
18/// FreeBSD doesn't support file range locking or block cloning (yet). We can emulate FreeBSD on
19/// platforms that have flock().
20pub(crate) fn emulate_freebsd() -> bool {
21    cfg_if! {
22        if #[cfg(target_os = "freebsd")] {
23            true
24        } else {
25            emulate_freebsd_from_env()
26        }
27    }
28}
29
30/// Whether to use flock() instead of file segment locking. flock() is not available on Windows.
31pub(crate) fn flocking() -> bool {
32    emulate_freebsd()
33}