Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 1479:1a3c6689ef2b
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.
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Fri, 28 Oct 2005 17:18:50 -0700 |
parents | f4250806dbeb |
children | 4d38b85e60aa |
comparison
equal
deleted
inserted
replaced
1478:e6dd91a88b57 | 1479:1a3c6689ef2b |
---|---|
375 d = os.path.dirname(f) | 375 d = os.path.dirname(f) |
376 if not os.path.isdir(d): | 376 if not os.path.isdir(d): |
377 os.makedirs(d) | 377 os.makedirs(d) |
378 else: | 378 else: |
379 if nlink > 1: | 379 if nlink > 1: |
380 file(f + ".tmp", "wb").write(file(f, "rb").read()) | 380 d, fn = os.path.split(f) |
381 rename(f+".tmp", f) | 381 fd, temp = tempfile.mkstemp(prefix=fn, dir=d) |
382 fp = os.fdopen(fd, "wb") | |
383 try: | |
384 fp.write(file(f, "rb").read()) | |
385 except: | |
386 try: os.unlink(temp) | |
387 except: pass | |
388 raise | |
389 fp.close() | |
390 rename(temp, f) | |
382 | 391 |
383 return file(f, mode) | 392 return file(f, mode) |
384 | 393 |
385 return o | 394 return o |
386 | 395 |