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")
|