comparison mercurial/util.py @ 13112:039a964dbbb3

opener: always reset flags on 'w'rite only the patcher needs to preserve flags on write
author Adrian Buehlmann <adrian@cadifra.com>
date Fri, 10 Dec 2010 15:14:05 +0100
parents a08b49d2f116
children 873c032c81b5
comparison
equal deleted inserted replaced
13111:560b8001f765 13112:039a964dbbb3
880 880
881 if not text and "b" not in mode: 881 if not text and "b" not in mode:
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.
889 if basename and mode not in ('r', 'rb'): 888 if basename and mode not in ('r', 'rb'):
890 if atomictemp: 889 if atomictemp:
891 if not os.path.isdir(dirname): 890 if not os.path.isdir(dirname):
892 makedirs(dirname, self.createmode) 891 makedirs(dirname, self.createmode)
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:
900 # nlinks() may behave differently for files on Windows 898 # nlinks() may behave differently for files on Windows
901 # shares if the file is open. 899 # shares if the file is open.
911 self._trustnlink = nlink > 1 or checknlink(f) 909 self._trustnlink = nlink > 1 or checknlink(f)
912 if nlink > 1 or not self._trustnlink: 910 if nlink > 1 or not self._trustnlink:
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):
923 self.auditor(dst) 918 self.auditor(dst)
924 linkname = os.path.join(self.base, dst) 919 linkname = os.path.join(self.base, dst)