mercurial/posix.py
changeset 32721 c2cb0de25120
parent 32394 38a2b9d90131
child 33651 739cc0f9cbb4
equal deleted inserted replaced
32720:0cd641bfbf57 32721:c2cb0de25120
    96 def isexec(f):
    96 def isexec(f):
    97     """check whether a file is executable"""
    97     """check whether a file is executable"""
    98     return (os.lstat(f).st_mode & 0o100 != 0)
    98     return (os.lstat(f).st_mode & 0o100 != 0)
    99 
    99 
   100 def setflags(f, l, x):
   100 def setflags(f, l, x):
   101     s = os.lstat(f).st_mode
   101     st = os.lstat(f)
       
   102     s = st.st_mode
   102     if l:
   103     if l:
   103         if not stat.S_ISLNK(s):
   104         if not stat.S_ISLNK(s):
   104             # switch file to link
   105             # switch file to link
   105             fp = open(f)
   106             fp = open(f)
   106             data = fp.read()
   107             data = fp.read()
   123         fp.write(data)
   124         fp.write(data)
   124         fp.close()
   125         fp.close()
   125         s = 0o666 & ~umask # avoid restatting for chmod
   126         s = 0o666 & ~umask # avoid restatting for chmod
   126 
   127 
   127     sx = s & 0o100
   128     sx = s & 0o100
       
   129     if st.st_nlink > 1 and bool(x) != bool(sx):
       
   130         # the file is a hardlink, break it
       
   131         with open(f, "rb") as fp:
       
   132             data = fp.read()
       
   133         unlink(f)
       
   134         with open(f, "wb") as fp:
       
   135             fp.write(data)
       
   136 
   128     if x and not sx:
   137     if x and not sx:
   129         # Turn on +x for every +r bit when making a file executable
   138         # Turn on +x for every +r bit when making a file executable
   130         # and obey umask.
   139         # and obey umask.
   131         os.chmod(f, s | (s & 0o444) >> 2 & ~umask)
   140         os.chmod(f, s | (s & 0o444) >> 2 & ~umask)
   132     elif not x and sx:
   141     elif not x and sx: