-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Potential data loss for files that changed on disk meanwhile after a backup was made #15749
Comments
Yes a check and a dialog would probably be ideal. Related: #14054 |
@Tyriar you do not really need to build any UI as we already have UI in place if you try to save with the file on disk having changed. All we need is to record the mtime of the file from where the backup started and then restore that when we restore the backup. Currently we just take the mtime from the file on disk and then restore the backup, but that is obviously not right. |
What is the current behavior if the file changes while it is open (is there some sort of inotify listener?)? It's probably better to catch this as soon as possible, rather than waiting for the user to try to save it, so that the user doesn't make massive amounts of changes in a potential three-way merge scenario. Maybe the requirements can be transferred over to the Backup service feature/story? |
From the HN post on 1.8 update:
Also, please don't take my comparisons to Sublime Text 3 as a negative implication. It simply instilled an expected behavior that is easy to convey by making the comparison... |
Here is how file changes outside of VSCode have an impact (there are file watchers in place that track changes to any file in the opened folder + any opened file that is not within the folder):
|
Hm, it's hard to say what happened because of the external interaction with Sublime Text. |
another option, don't save modified files. Like 99% of apps, just pop up a dialog on quit "You have unsaved files". Could be simple "You have modified buffers, Exit Y? N?" or more complex, example I prefer that solution, or at least the option (VSCode asking on exit and never saving unmodified buffers) over trying to make it's auto saving on quit work. Not saying that feature shouldn't be fixed, only saying that I'd prefer to turn off. Saving backups is good, restoring backups automatically that might be out of date, not so much. |
@greggman you should turn it off:
|
I hope this will be addressed soon. The upcoming 1.34 release brings better dirty write handling in scenarios where |
+1 on this is a data loss issue. I lost about a day's worth of work yesterday. VSC was my favorite editor. Now I will have to think twice about opening VSC again and just recommended VSC to friends this week and now have to warn them :) What's holding us from implementing a fix? Looks like the bug is open for more than 2 years. Thanks, |
@gjsjohnmurray I disagree that the recent changes in the file service make this bug appear anymore often than before. In fact, up until now, files saved through custom file providers (extensions) never had any protection of dirty writes, so I would argue we improved the behaviour here for custom file providers and not the other way around. That said, we always had hot-exit for files with custom scheme, nothing changed there. @erturkk how did that happen exactly? I think in most cases at work, files are under some kind of source control system giving you the ability to see the changes before pushing them, no? |
@bpasero My thinking is, once dirty write protection for custom file providers lands in 1.34 more people will be willing to use VSCode in scenarios where they need that protection. And then if they're configured to use hot-exit (which is the default), one day they may get bitten by this bug. |
@bpasero this bug hit me before I even checked in the file for the first time. Source control might help recover the file but that will be after the fact and depending on how recent the check-in was, one will lose data. You should be able to replicate the problem easily. Let me define two actions:
Open a file in VSC, edit it but don't save it and don't close the tab. Quit VSC. Use another editor to open the same file, modify it, save it, close this editor. Then open VSC again, and you will see the file is already opened but it does not reflect the changes made with the other editor. If you save the file now, you just overwrote the changes you made externally. For me, I opened the file in VSC Thursday. I don't remember if I made any changes or not, but I quit VSC while the tab was open (this step is important). On Friday, I modified the same file with another editor whole day. Friday evening, I wanted to work on the same file and check in the first version. So I opened VSC, file was already opened so I started modifying from the top (i.e. add change comments, etc.). As I was editing I was also periodically saving (CTRL-S). Once I reached to the section of the code where I made changes on Friday, I realized the file was still the old file. Then it hit me changes I made on Friday were gone :) Hope this helps, let me know if you need more info. |
For me the steps were
If I now save in VSC and commit I just screwed my repo. There is no other software on my enter system in the history of owning software for 35 years that has this behavior. I get that it's an interesting idea but it should arguably be off by default and like most software ask if you want to save changed files on exit. Again I know that's an option. I'd argue it should be the default since it's what people are used to coming from other software. Otherwise if you want a fix then, at step 3 above, VSC should notice the file changed (maybe by date if not by content) and warn before loading the backed up file. As it IT SILENTLY DELTETS DATA How many more people have to lose their work before this gets resolved? |
VSC could calculate a hash when file is opened for edited and save this if user quits without saving. Upon restarting, we compare and if different, then issue a warning to the user. |
#73123 is up to fix this. |
via #73123 |
Following scenario:
=> this basically bypasses our check to prevent dirty writes to files that have changed meanwhile
=> maybe the backup should store the etag of the file (mtime + size) as part of the backup in the meta data section of the backup (where we should also store the file path) so that this check is not bypassed.
The text was updated successfully, but these errors were encountered: