use std::fs::File;
use std::path::Path;
use crate::error::{ImageError, ImageResult};
pub(crate) fn open_lock_file(path: &Path) -> ImageResult<File> {
microsandbox_utils::process_lock::open_lock_file(path).map_err(|e| ImageError::Cache {
path: path.to_path_buf(),
source: e,
})
}
pub(crate) fn lock_exclusive(file: &File) -> ImageResult<()> {
lock_exclusive_by_file(file)
}
pub(crate) fn flock_unlock(file: &File) -> ImageResult<()> {
microsandbox_utils::process_lock::unlock(file).map_err(ImageError::Io)
}
#[cfg(unix)]
fn lock_exclusive_by_file(file: &File) -> ImageResult<()> {
microsandbox_utils::process_lock::lock_exclusive(file).map_err(ImageError::Io)
}
#[cfg(windows)]
fn lock_exclusive_by_file(file: &File) -> ImageResult<()> {
microsandbox_utils::process_lock::lock_exclusive(file).map_err(ImageError::Io)
}