Mercurial > public > mercurial-scm > hg-stable
diff mercurial/patch.py @ 9586:d08099e74b81
patch: handle symlink updates/replacements (issue1785)
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Thu, 15 Oct 2009 23:15:30 +0200 |
parents | ea1935e2020a |
children | a981ddb16b80 |
line wrap: on
line diff
--- a/mercurial/patch.py Thu Oct 15 23:15:30 2009 +0200 +++ b/mercurial/patch.py Thu Oct 15 23:15:30 2009 +0200 @@ -301,7 +301,14 @@ fp.close() def writelines(self, fname, lines): - fp = self.opener(fname, 'w') + # Ensure supplied data ends in fname, being a regular file or + # a symlink. updatedir() will -too magically- take care of + # setting it to the proper type afterwards. + islink = os.path.islink(fname) + if islink: + fp = cStringIO.StringIO() + else: + fp = self.opener(fname, 'w') try: if self.eol and self.eol != '\n': for l in lines: @@ -310,6 +317,8 @@ fp.write(l) else: fp.writelines(lines) + if islink: + self.opener.symlink(fp.getvalue(), fname) finally: fp.close()