Mercurial > public > mercurial-scm > hg-stable
diff mercurial/posix.py @ 32741:c2cb0de25120
chmod: create a new file when flags are set on a hardlinked file
For performance reasons we have several repositories where the files in the working
directory of 1 repo are hardlinks to the files of the other repo
When an update in one repo results in a chmod of a such a file, the hardlink
has to be deleted and replaced by a regular file to make sure that the change
does not happen in the other repo
author | Koen Van Hoof <koen.van_hoof@nokia.com> |
---|---|
date | Wed, 26 Apr 2017 16:05:22 +0200 |
parents | 38a2b9d90131 |
children | 739cc0f9cbb4 |
line wrap: on
line diff
--- a/mercurial/posix.py Wed Jun 07 21:17:24 2017 -0700 +++ b/mercurial/posix.py Wed Apr 26 16:05:22 2017 +0200 @@ -98,7 +98,8 @@ return (os.lstat(f).st_mode & 0o100 != 0) def setflags(f, l, x): - s = os.lstat(f).st_mode + st = os.lstat(f) + s = st.st_mode if l: if not stat.S_ISLNK(s): # switch file to link @@ -125,6 +126,14 @@ s = 0o666 & ~umask # avoid restatting for chmod sx = s & 0o100 + if st.st_nlink > 1 and bool(x) != bool(sx): + # the file is a hardlink, break it + with open(f, "rb") as fp: + data = fp.read() + unlink(f) + with open(f, "wb") as fp: + fp.write(data) + if x and not sx: # Turn on +x for every +r bit when making a file executable # and obey umask.