mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 15:27:13 +03:00
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.
This commit is contained in:
parent
87e35504f4
commit
bc51f024c7
@ -377,8 +377,17 @@ def opener(base):
|
||||
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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user