foundry_test_utils/
fd_lock.rs

1//! File locking utilities.
2
3use crate::util::pretty_err;
4use std::{
5    fs::{File, OpenOptions},
6    path::Path,
7};
8
9pub use fd_lock::*;
10
11/// Creates a new lock file at the given path.
12pub fn new_lock(lock_path: impl AsRef<Path>) -> RwLock<File> {
13    fn new_lock(lock_path: &Path) -> RwLock<File> {
14        let lock_file = pretty_err(
15            lock_path,
16            OpenOptions::new().read(true).write(true).create(true).truncate(false).open(lock_path),
17        );
18        RwLock::new(lock_file)
19    }
20    new_lock(lock_path.as_ref())
21}