#[cfg(unix)]
use super::File;
use super::Path;
#[cfg(all(unix, test))]
thread_local! {
pub(super) static FAIL_NEXT_PARENT_SYNC: std::cell::Cell<bool> =
const { std::cell::Cell::new(false) };
}
#[cfg(unix)]
pub(super) fn sync_parent_directory(path: &Path) -> std::io::Result<()> {
#[cfg(test)]
if FAIL_NEXT_PARENT_SYNC.with(std::cell::Cell::take) {
return Err(std::io::Error::other(
"injected parent directory sync failure",
));
}
let parent = path.parent().ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"path has no parent directory",
)
})?;
File::open(parent)?.sync_all()
}
#[cfg(not(unix))]
pub(super) fn sync_parent_directory(_path: &Path) -> std::io::Result<()> {
Ok(())
}