fix: nippy jar error access is denied. os error 5 (#9747) (#10672)

Co-authored-by: joshieDo <93316087+joshieDo@users.noreply.github.com>
This commit is contained in:
Alex Zammit
2024-09-04 22:03:04 +02:00
committed by GitHub
parent 3105320d94
commit 86a2ac6fa2

View File

@@ -21,6 +21,11 @@ use std::{
ops::Range,
path::{Path, PathBuf},
};
// Windows specific extension for std::fs
#[cfg(windows)]
use std::os::windows::prelude::OpenOptionsExt;
use tracing::*;
pub mod compression;
@@ -261,6 +266,16 @@ impl<H: NippyJarHeader> NippyJar<H> {
// fsync() dir
if let Some(parent) = tmp_path.parent() {
//custom_flags() is only available on Windows
#[cfg(windows)]
OpenOptions::new()
.read(true)
.write(true)
.custom_flags(0x02000000) // FILE_FLAG_BACKUP_SEMANTICS
.open(parent)?
.sync_all()?;
#[cfg(not(windows))]
OpenOptions::new().read(true).open(parent)?.sync_all()?;
}
Ok(())