use std::fs::File;
use std::path::Path;
pub fn replace_file(from: &Path, to: &Path) -> std::io::Result<()> {
std::fs::rename(from, to)
}
pub fn sync_parent_directory(path: &Path) -> std::io::Result<()> {
let Some(parent) = path.parent() else {
return Ok(());
};
open_directory_for_sync(parent).and_then(|directory| directory.sync_all())
}
fn open_directory_for_sync(path: &Path) -> std::io::Result<File> {
#[cfg(windows)]
{
use std::fs::OpenOptions;
use std::os::windows::fs::OpenOptionsExt;
const GENERIC_READ: u32 = 0x8000_0000;
const GENERIC_WRITE: u32 = 0x4000_0000;
const FILE_FLAG_BACKUP_SEMANTICS: u32 = 0x0200_0000;
OpenOptions::new()
.access_mode(GENERIC_READ | GENERIC_WRITE)
.custom_flags(FILE_FLAG_BACKUP_SEMANTICS)
.open(path)
}
#[cfg(not(windows))]
File::open(path)
}