Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 14008:da65edcac72a
atomictempfile: rewrite docstring to clarify rename() vs. close().
author | Greg Ward <greg@gerg.ca> |
---|---|
date | Sun, 24 Apr 2011 17:30:50 -0400 |
parents | d764463b433e |
children | e4bfb9c337f3 |
comparison
equal
deleted
inserted
replaced
14007:d764463b433e | 14008:da65edcac72a |
---|---|
717 except: pass | 717 except: pass |
718 raise | 718 raise |
719 return temp | 719 return temp |
720 | 720 |
721 class atomictempfile(object): | 721 class atomictempfile(object): |
722 """file-like object that atomically updates a file | 722 '''writeable file object that atomically updates a file |
723 | 723 |
724 All writes will be redirected to a temporary copy of the original | 724 All writes will go to a temporary copy of the original file. Call |
725 file. When rename is called, the copy is renamed to the original | 725 rename() when you are done writing, and atomictempfile will rename |
726 name, making the changes visible. | 726 the temporary copy to the original name, making the changes visible. |
727 """ | 727 |
728 Unlike other file-like objects, close() discards your writes by | |
729 simply deleting the temporary file. | |
730 ''' | |
728 def __init__(self, name, mode='w+b', createmode=None): | 731 def __init__(self, name, mode='w+b', createmode=None): |
729 self.__name = name # permanent name | 732 self.__name = name # permanent name |
730 self._tempname = mktempcopy(name, emptyok=('w' in mode), | 733 self._tempname = mktempcopy(name, emptyok=('w' in mode), |
731 createmode=createmode) | 734 createmode=createmode) |
732 self._fp = posixfile(self._tempname, mode) | 735 self._fp = posixfile(self._tempname, mode) |