equal
deleted
inserted
replaced
4 # Copyright 2007 Chris Mason <chris.mason@oracle.com> |
4 # Copyright 2007 Chris Mason <chris.mason@oracle.com> |
5 # |
5 # |
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 _ |
13 from node import hex, nullid, short |
13 from node import hex, nullid, short |
14 import base85, mdiff, util, diffhelpers, copies, encoding |
14 import base85, mdiff, util, diffhelpers, copies, encoding |
427 |
427 |
428 def writelines(self, fname, lines): |
428 def writelines(self, fname, lines): |
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': |
439 eol = self.eol |
445 eol = self.eol |
440 elif self.eolmode == 'crlf': |
446 elif self.eolmode == 'crlf': |
449 fp.write(l) |
455 fp.write(l) |
450 else: |
456 else: |
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 |
457 def unlink(self, fname): |
465 def unlink(self, fname): |
458 os.unlink(fname) |
466 os.unlink(fname) |