Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions crates/rnote-ui/src/canvas/imexport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,28 +232,39 @@ impl RnCanvas {
let file_write_operation = async move {
let bytes = rnote_bytes_receiver.await??;
self.set_output_file_expect_write(true);

let mut temp_path = file_path.to_path_buf();
temp_path.set_extension("tmp");

let mut write_file = async_fs::OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(&file_path)
.open(&temp_path)
.await
.context(format!(
"Failed to create/open/truncate file for path '{}'",
file_path.display()
temp_path.display()
))?;
if !skip_set_output_file {
// this installs the file watcher.
self.set_output_file(Some(file.to_owned()));
}
write_file.write_all(&bytes).await.context(format!(
"Failed to write bytes to file with path '{}'",
file_path.display()
temp_path.display()
))?;
write_file.sync_all().await.context(format!(
"Failed to sync file after writing with path '{}'",
file_path.display()
temp_path.display()
))?;
// If everything goes well, replace the original file
async_fs::rename(&temp_path, &file_path)
.await
.context(format!(
"Failed to rename temporary file to '{}'",
file_path.display()
))?;
Ok(())
};

Expand Down