forked from 1b-agent/opencadstudio-upstream
fix(save): retry the atomic replace while the drawing is briefly in use
Sync clients, indexers and virus scanners open a freshly written file for a moment without delete sharing, which refuses ReplaceFileW with a sharing violation. Saving straight after Save As into a Dropbox folder hit this every time. The replace now retries for about two seconds before reporting the file in use. Fixes #1712 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
88803cd692
commit
9e31af3ff2
1 file changed
+11
-1
+11
-1
@@ -2254,7 +2254,17 @@ fn replace_save_file(temp_path: &Path, path: &Path) -> std::io::Result<()> {
|
|||||||
// drawing that was hidden before the save stays hidden. (#1414)
|
// drawing that was hidden before the save stays hidden. (#1414)
|
||||||
let was_hidden = std::fs::metadata(path)
|
let was_hidden = std::fs::metadata(path)
|
||||||
.is_ok_and(|meta| meta.file_attributes() & FILE_ATTRIBUTE_HIDDEN != 0);
|
.is_ok_and(|meta| meta.file_attributes() & FILE_ATTRIBUTE_HIDDEN != 0);
|
||||||
replace_save_file_inner(temp_path, path)?;
|
// Sync clients (Dropbox, OneDrive), indexers and virus scanners open a
|
||||||
|
// freshly written drawing for a moment without delete sharing, which
|
||||||
|
// refuses the replace. Retry briefly before reporting the file in use.
|
||||||
|
let mut attempt = 0;
|
||||||
|
while let Err(error) = replace_save_file_inner(temp_path, path) {
|
||||||
|
attempt += 1;
|
||||||
|
if attempt >= 10 || !replace_error_is_file_in_use(&error) {
|
||||||
|
return Err(error);
|
||||||
|
}
|
||||||
|
std::thread::sleep(std::time::Duration::from_millis(200));
|
||||||
|
}
|
||||||
if !was_hidden {
|
if !was_hidden {
|
||||||
if let Ok(meta) = std::fs::metadata(path) {
|
if let Ok(meta) = std::fs::metadata(path) {
|
||||||
let attributes = meta.file_attributes();
|
let attributes = meta.file_attributes();
|
||||||
|
|||||||
Reference in new issue
Block a user