Show More
@@ -6,7 +6,7 b'' | |||||
6 | # This software may be used and distributed according to the terms of the |
|
6 | # This software may be used and distributed according to the terms of the | |
7 | # GNU General Public License version 2 or any later version. |
|
7 | # GNU General Public License version 2 or any later version. | |
8 |
|
8 | |||
9 | import cStringIO, email.Parser, os, re |
|
9 | import cStringIO, email.Parser, os, errno, re | |
10 | import tempfile, zlib |
|
10 | import tempfile, zlib | |
11 |
|
11 | |||
12 | from i18n import _ |
|
12 | from i18n import _ | |
@@ -429,10 +429,16 b' class patchfile(object):' | |||||
429 | # Ensure supplied data ends in fname, being a regular file or |
|
429 | # Ensure supplied data ends in fname, being a regular file or | |
430 | # a symlink. cmdutil.updatedir will -too magically- take care |
|
430 | # a symlink. cmdutil.updatedir will -too magically- take care | |
431 | # of setting it to the proper type afterwards. |
|
431 | # of setting it to the proper type afterwards. | |
|
432 | st_mode = None | |||
432 | islink = os.path.islink(fname) |
|
433 | islink = os.path.islink(fname) | |
433 | if islink: |
|
434 | if islink: | |
434 | fp = cStringIO.StringIO() |
|
435 | fp = cStringIO.StringIO() | |
435 | else: |
|
436 | else: | |
|
437 | try: | |||
|
438 | st_mode = os.lstat(fname).st_mode & 0777 | |||
|
439 | except OSError, e: | |||
|
440 | if e.errno != errno.ENOENT: | |||
|
441 | raise | |||
436 | fp = self.opener(fname, 'w') |
|
442 | fp = self.opener(fname, 'w') | |
437 | try: |
|
443 | try: | |
438 | if self.eolmode == 'auto': |
|
444 | if self.eolmode == 'auto': | |
@@ -451,6 +457,8 b' class patchfile(object):' | |||||
451 | fp.writelines(lines) |
|
457 | fp.writelines(lines) | |
452 | if islink: |
|
458 | if islink: | |
453 | self.opener.symlink(fp.getvalue(), fname) |
|
459 | self.opener.symlink(fp.getvalue(), fname) | |
|
460 | if st_mode is not None: | |||
|
461 | os.chmod(fname, st_mode) | |||
454 | finally: |
|
462 | finally: | |
455 | fp.close() |
|
463 | fp.close() | |
456 |
|
464 |
@@ -882,7 +882,6 b' class opener(object):' | |||||
882 | mode += "b" # for that other OS |
|
882 | mode += "b" # for that other OS | |
883 |
|
883 | |||
884 | nlink = -1 |
|
884 | nlink = -1 | |
885 | st_mode = None |
|
|||
886 | dirname, basename = os.path.split(f) |
|
885 | dirname, basename = os.path.split(f) | |
887 | # If basename is empty, then the path is malformed because it points |
|
886 | # If basename is empty, then the path is malformed because it points | |
888 | # to a directory. Let the posixfile() call below raise IOError. |
|
887 | # to a directory. Let the posixfile() call below raise IOError. | |
@@ -893,7 +892,6 b' class opener(object):' | |||||
893 | return atomictempfile(f, mode, self.createmode) |
|
892 | return atomictempfile(f, mode, self.createmode) | |
894 | try: |
|
893 | try: | |
895 | if 'w' in mode: |
|
894 | if 'w' in mode: | |
896 | st_mode = os.lstat(f).st_mode & 0777 |
|
|||
897 | os.unlink(f) |
|
895 | os.unlink(f) | |
898 | nlink = 0 |
|
896 | nlink = 0 | |
899 | else: |
|
897 | else: | |
@@ -913,10 +911,7 b' class opener(object):' | |||||
913 | rename(mktempcopy(f), f) |
|
911 | rename(mktempcopy(f), f) | |
914 | fp = posixfile(f, mode) |
|
912 | fp = posixfile(f, mode) | |
915 | if nlink == 0: |
|
913 | if nlink == 0: | |
916 | if st_mode is None: |
|
914 | self._fixfilemode(f) | |
917 | self._fixfilemode(f) |
|
|||
918 | else: |
|
|||
919 | os.chmod(f, st_mode) |
|
|||
920 | return fp |
|
915 | return fp | |
921 |
|
916 | |||
922 | def symlink(self, src, dst): |
|
917 | def symlink(self, src, dst): |
General Comments 0
You need to be logged in to leave comments.
Login now