[Python-bugs-list] [ python-Bugs-541730 ] IDLE can clobber files
noreply@sourceforge.net
noreply@sourceforge.net
Tue, 09 Apr 2002 13:14:16 -0700
Bugs item #541730, was opened at 2002-04-09 20:14
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=541730&group_id=5470
Category: IDLE
Group: Python 2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Ben Darnell (bgdarnel)
Assigned to: Nobody/Anonymous (nobody)
Summary: IDLE can clobber files
Initial Comment:
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")
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=541730&group_id=5470