mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-18 06:22:28 +03:00
Merge pull request #3620 from gitbutlerapp/add-windows-fs-write-support
skip tempfile under windows
This commit is contained in:
commit
470f89de01
@ -58,13 +58,21 @@ pub(crate) fn write<P: AsRef<Path>>(
|
|||||||
file_path: P,
|
file_path: P,
|
||||||
contents: impl AsRef<[u8]>,
|
contents: impl AsRef<[u8]>,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let mut temp_file = gix::tempfile::new(
|
#[cfg(windows)]
|
||||||
file_path.as_ref().parent().unwrap(),
|
{
|
||||||
ContainingDirectory::Exists,
|
Ok(std::fs::write(file_path, contents)?)
|
||||||
AutoRemove::Tempfile,
|
}
|
||||||
)?;
|
|
||||||
temp_file.write_all(contents.as_ref())?;
|
#[cfg(not(windows))]
|
||||||
Ok(persist_tempfile(temp_file, file_path)?)
|
{
|
||||||
|
let mut temp_file = gix::tempfile::new(
|
||||||
|
file_path.as_ref().parent().unwrap(),
|
||||||
|
ContainingDirectory::Exists,
|
||||||
|
AutoRemove::Tempfile,
|
||||||
|
)?;
|
||||||
|
temp_file.write_all(contents.as_ref())?;
|
||||||
|
Ok(persist_tempfile(temp_file, file_path)?)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Write a single file so that the write either fully succeeds, or fully fails,
|
/// Write a single file so that the write either fully succeeds, or fully fails,
|
||||||
@ -73,13 +81,25 @@ pub(crate) fn create_dirs_then_write<P: AsRef<Path>>(
|
|||||||
file_path: P,
|
file_path: P,
|
||||||
contents: impl AsRef<[u8]>,
|
contents: impl AsRef<[u8]>,
|
||||||
) -> std::io::Result<()> {
|
) -> std::io::Result<()> {
|
||||||
let mut temp_file = gix::tempfile::new(
|
#[cfg(windows)]
|
||||||
file_path.as_ref().parent().unwrap(),
|
{
|
||||||
ContainingDirectory::CreateAllRaceProof(Retries::default()),
|
let dir = file_path.as_ref().parent().unwrap();
|
||||||
AutoRemove::Tempfile,
|
if !dir.exists() {
|
||||||
)?;
|
std::fs::create_dir_all(dir)?;
|
||||||
temp_file.write_all(contents.as_ref())?;
|
}
|
||||||
persist_tempfile(temp_file, file_path)
|
std::fs::write(file_path, contents)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
{
|
||||||
|
let mut temp_file = gix::tempfile::new(
|
||||||
|
file_path.as_ref().parent().unwrap(),
|
||||||
|
ContainingDirectory::CreateAllRaceProof(Retries::default()),
|
||||||
|
AutoRemove::Tempfile,
|
||||||
|
)?;
|
||||||
|
temp_file.write_all(contents.as_ref())?;
|
||||||
|
persist_tempfile(temp_file, file_path)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn persist_tempfile(
|
fn persist_tempfile(
|
||||||
|
Loading…
Reference in New Issue
Block a user