mercurial/posix.py
changeset 41289 593f6359681d
parent 40792 47e3f554df35
child 41504 587a3c976892
equal deleted inserted replaced
41288:17941fc53ae9 41289:593f6359681d
   151         os.chmod(f, s | (s & 0o444) >> 2 & ~umask)
   151         os.chmod(f, s | (s & 0o444) >> 2 & ~umask)
   152     elif not x and sx:
   152     elif not x and sx:
   153         # Turn off all +x bits
   153         # Turn off all +x bits
   154         os.chmod(f, s & 0o666)
   154         os.chmod(f, s & 0o666)
   155 
   155 
   156 def copymode(src, dst, mode=None):
   156 def copymode(src, dst, mode=None, enforcewritable=False):
   157     '''Copy the file mode from the file at path src to dst.
   157     '''Copy the file mode from the file at path src to dst.
   158     If src doesn't exist, we're using mode instead. If mode is None, we're
   158     If src doesn't exist, we're using mode instead. If mode is None, we're
   159     using umask.'''
   159     using umask.'''
   160     try:
   160     try:
   161         st_mode = os.lstat(src).st_mode & 0o777
   161         st_mode = os.lstat(src).st_mode & 0o777
   164             raise
   164             raise
   165         st_mode = mode
   165         st_mode = mode
   166         if st_mode is None:
   166         if st_mode is None:
   167             st_mode = ~umask
   167             st_mode = ~umask
   168         st_mode &= 0o666
   168         st_mode &= 0o666
   169     os.chmod(dst, st_mode)
   169 
       
   170     new_mode = st_mode
       
   171 
       
   172     if enforcewritable:
       
   173         new_mode |= stat.S_IWUSR
       
   174 
       
   175     os.chmod(dst, new_mode)
   170 
   176 
   171 def checkexec(path):
   177 def checkexec(path):
   172     """
   178     """
   173     Check whether the given path is on a filesystem with UNIX-like exec flags
   179     Check whether the given path is on a filesystem with UNIX-like exec flags
   174 
   180