mercurial/posix.py
changeset 36303 ed95758addf3
parent 35513 c4caf530b1c7
child 36415 0cb09c322647
equal deleted inserted replaced
36302:ba1807d9a846 36303:ed95758addf3
   111     st = os.lstat(f)
   111     st = os.lstat(f)
   112     s = st.st_mode
   112     s = st.st_mode
   113     if l:
   113     if l:
   114         if not stat.S_ISLNK(s):
   114         if not stat.S_ISLNK(s):
   115             # switch file to link
   115             # switch file to link
   116             fp = open(f)
   116             fp = open(f, 'rb')
   117             data = fp.read()
   117             data = fp.read()
   118             fp.close()
   118             fp.close()
   119             unlink(f)
   119             unlink(f)
   120             try:
   120             try:
   121                 os.symlink(data, f)
   121                 os.symlink(data, f)
   122             except OSError:
   122             except OSError:
   123                 # failed to make a link, rewrite file
   123                 # failed to make a link, rewrite file
   124                 fp = open(f, "w")
   124                 fp = open(f, "wb")
   125                 fp.write(data)
   125                 fp.write(data)
   126                 fp.close()
   126                 fp.close()
   127         # no chmod needed at this point
   127         # no chmod needed at this point
   128         return
   128         return
   129     if stat.S_ISLNK(s):
   129     if stat.S_ISLNK(s):
   130         # switch link to file
   130         # switch link to file
   131         data = os.readlink(f)
   131         data = os.readlink(f)
   132         unlink(f)
   132         unlink(f)
   133         fp = open(f, "w")
   133         fp = open(f, "wb")
   134         fp.write(data)
   134         fp.write(data)
   135         fp.close()
   135         fp.close()
   136         s = 0o666 & ~umask # avoid restatting for chmod
   136         s = 0o666 & ~umask # avoid restatting for chmod
   137 
   137 
   138     sx = s & 0o100
   138     sx = s & 0o100