Issue 541730: IDLE can clobber files (original) (raw)

Issue541730

Created on 2002-04-09 20:14 by bgdarnel, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Messages (3)
msg10228 - (view) Author: Ben Darnell (bgdarnel) Date: 2002-04-09 20:14
I just lost some work today when IDLE failed to save my file. The file was truncated to 0 bytes, so it wasn't recoverable by the recycle bin or anything like that. I was running Python 2.2 on Win2kPro. There was no error message, although IDLE seemed to realize that the save failed - the asterisk remained in the title bar. I tried saving to a different name, but that didn't work either (although a zero-byte file was created with the new name). I know this isn't enough for you to go on to fix the bug; if I encounter the error again I will inspect the situation more closely. In order to prevent data loss like this in the future, I'd like to see IDLE make a backup of files before it saves over them. I submit the following (untested) patch: --- IOBinding.py.orig Tue Apr 9 15:56:00 2002 +++ IOBinding.py Tue Apr 9 15:59:07 2002 @@ -148,6 +148,11 @@ def writefile(self, filename): self.fixlastline() + try: + if os.path.exists(filename): + os.rename(filename, filename+'~') + except IOError: + pass try: f = open(filename, "w") chars = self.text.get("1.0", "end-1c")
msg10229 - (view) Author: Ben Darnell (bgdarnel) Date: 2002-04-10 15:33
Logged In: YES user_id=280 On further consideration, it's not the lack of backups that causes the problem, it's the fact that an exception in self.text.get can wipe out the file. Moving the self.text.get call to before the file is opened would make it safe.
msg10230 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-04-15 00:20
Logged In: YES user_id=6380 I've fixed this using your later suggestion. We really should do something better, but that requires more thought and decisions, so I'm putting that off until the next serious IDLE overhaul.
History
Date User Action Args
2022-04-10 16:05:12 admin set github: 36403
2002-04-09 20:14:16 bgdarnel create