Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/patch.py @ 5477:bff41174563f
Only set mode of new patch if the target file was removed before.
If the file is writable by the user, but owned by a different user, the
chmod will otherwise fail with "Operation not permitted".
Additionally make very sure that the file is only written if either the number
of links is <= 1 or the file was successfully removed.
Maybe this minimal COW code should be replaced by something from util.
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Thu, 25 Oct 2007 19:40:56 +0200 |
parents | 9b469bdb1ce1 |
children | 003d1f174fe1 |
comparison
equal
deleted
inserted
replaced
5476:b3afa6725082 | 5477:bff41174563f |
---|---|
7 # of the GNU General Public License, incorporated herein by reference. | 7 # of the GNU General Public License, incorporated herein by reference. |
8 | 8 |
9 from i18n import _ | 9 from i18n import _ |
10 from node import * | 10 from node import * |
11 import base85, cmdutil, mdiff, util, context, revlog, diffhelpers | 11 import base85, cmdutil, mdiff, util, context, revlog, diffhelpers |
12 import cStringIO, email.Parser, os, popen2, re, sha | 12 import cStringIO, email.Parser, os, popen2, re, sha, errno |
13 import sys, tempfile, zlib | 13 import sys, tempfile, zlib |
14 | 14 |
15 class PatchError(Exception): | 15 class PatchError(Exception): |
16 pass | 16 pass |
17 | 17 |
400 if not dest: | 400 if not dest: |
401 dest = self.fname | 401 dest = self.fname |
402 st = None | 402 st = None |
403 try: | 403 try: |
404 st = os.lstat(dest) | 404 st = os.lstat(dest) |
405 if st.st_nlink > 1: | 405 except OSError, inst: |
406 os.unlink(dest) | 406 if inst.errno != errno.ENOENT: |
407 except: pass | 407 raise |
408 if st and st.st_nlink > 1: | |
409 os.unlink(dest) | |
408 fp = file(dest, 'wb') | 410 fp = file(dest, 'wb') |
409 if st: | 411 if st and st.st_nlink > 1: |
410 os.chmod(dest, st.st_mode) | 412 os.chmod(dest, st.st_mode) |
411 fp.writelines(self.lines) | 413 fp.writelines(self.lines) |
412 fp.close() | 414 fp.close() |
413 | 415 |
414 def close(self): | 416 def close(self): |