-
-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data loss on Rename #986
Comments
I took a quick look just now and not seeing what you see, although I do see some funky behavior.
This is all as it should be... But what I see is that the original file remains which is not correct. This doesn't sound what you're describing - can you walk me through your scenario, if different? I suspect this might be a timing bug due to async changes a while back. I'll take a closer look at the code tomorrow to see why the file is not actually deleting. |
I could send a video if it helps. I followed your steps and saw the same data loss issue. I do also see that the old file is still there on disk, and does have the changes saved there. I've tried rebooting and nothing changed. Should note I'm running 2.7.4 on Windows 10 with a fast SSD. Definitely could see some timing issue causing both outcomes, especially if you are relying on a file copy to do the rename. Perhaps you are doing an async write followed by a copy, and the copy happens before the write? |
Took a look at the code and sure enough the code wasn't properly updated when the async transition was made - what worked sync didn't work async anymore as timing issues with background file operations where wreaking havoc files not being completely moved around yet. The fix was to rearrange the operations to make the close operation happen much sooner and adding an additional idle state to allow the file IO to catch up. In my testing with small and largish (20k) files I no longer see any issues but give this a shot with The code fix was to explicitly wait after the close operation and add the extra (nasty looking dispatcher call) wait state: if (File.Exists(fileItem.FullPath))
{
// If tab was open - close it
tab = Window.GetTabFromFilename(oldFile);
if (tab != null)
{
await Window.CloseTab(oldFile);
await Dispatcher.Yield(DispatcherPriority.ApplicationIdle);
}
if (!File.Exists(newPath))
File.Move(fileItem.FullPath, newPath);
else
File.Copy(fileItem.FullPath, newPath, true);
await Dispatcher.Yield(DispatcherPriority.ApplicationIdle);
} It wouldn't work correctly without the Dispatcher call in place. |
Great, tested the pre-release version and it seems fixed. Thanks! |
Edit a markdown file but do not save. Select Rename in the file and folder browser and rename the markdown file. Markdown Monster will prompt you to save your changes, select Yes. Notice that the file is renamed, and the changes are lost.
Expected result: file should be renamed, and the changes saved
The text was updated successfully, but these errors were encountered: