# HG changeset patch
# User Benoit Boissinot <benoit.boissinot@xxxxxxxxxxxx>
# Node ID 68e797ee9332f4687e4c98849e29429882a22c57
# Parent df7fb20c4bacd0ff942ab45dea7cd9b8235dd796
fix a bug where hg could remove file ending with .tmp
util.opener used a fixed filename for writing tempfile
instead of using the tempfile module.
diff -r df7fb20c4bac -r 68e797ee9332 mercurial/util.py
--- a/mercurial/util.py Fri Oct 28 19:47:31 2005 +0200
+++ b/mercurial/util.py Fri Oct 28 20:31:56 2005 +0200
@@ -377,8 +377,17 @@
os.makedirs(d)
else:
if nlink > 1:
- file(f + ".tmp", "wb").write(file(f, "rb").read())
- rename(f+".tmp", f)
+ d, fn = os.path.split(f)
+ fd, temp = tempfile.mkstemp(prefix=fn, dir=d)
+ fp = os.fdopen(fd, "wb")
+ try:
+ fp.write(file(f, "rb").read())
+ except:
+ try: os.unlink(temp)
+ except: pass
+ raise
+ fp.close()
+ rename(temp, f)
return file(f, mode)
|