[PATCH] hardlink: check directory's st_dev instead of files

Jun Wu quark at fb.com
Sun Mar 26 12:53:11 EDT 2017


Excerpts from Yuya Nishihara's message of 2017-03-26 20:50:06 +0900:
> On Sat, 25 Mar 2017 13:58:33 -0700, Jun Wu wrote:
> > # HG changeset patch
> > # User Jun Wu <quark at fb.com>
> > # Date 1490475382 25200
> > #      Sat Mar 25 13:56:22 2017 -0700
> > # Node ID b288a611eff957d3f03b06c419c16721f4fb5016
> > # Parent  c60091fa1426892552dd6c0dd4b9c49e3c3da045
> > # Available At https://bitbucket.org/quark-zju/hg-draft 
> > #              hg pull https://bitbucket.org/quark-zju/hg-draft  -r b288a611eff9
> > hardlink: check directory's st_dev instead of files
> > 
> > Previously, copyfiles will compare src's st_dev with dirname(dst)'s st_dev,
> > to decide whether to enable hardlink or not.
> > 
> > That could have issues on Linux's overlayfs, where stating directories could
> > result in different st_dev from files, even if both the directories and the
> > files exist in the overlay's upperdir.
> > 
> > This patch fixes it by checking dirname(src) instead. That fixes
> > test-hardlinks.t running on common Docker environment.
> > 
> > The "copyfiles" seems to need some extra cleanups, for example, the
> > "hardlink" check should only happen if it's copying a file, not a directory.
> > That cleanup will be done later.
> > 
> > diff --git a/mercurial/util.py b/mercurial/util.py
> > --- a/mercurial/util.py
> > +++ b/mercurial/util.py
> > @@ -1125,5 +1125,5 @@ def copyfiles(src, dst, hardlink=None, p
> >  
> >      if hardlink is None:
> > -        hardlink = (os.stat(src).st_dev ==
> > +        hardlink = (os.stat(os.path.dirname(src)).st_dev ==
> >                      os.stat(os.path.dirname(dst)).st_dev)
> 
> Does this work if src is a mount point?

I have thought the same problem. I think the "st_dev" check should be moved
to the "if src is a file" block. If src is a directory, the check should be
avoided. I'll send follow-ups as the commit message suggests.

And it seems not harmful if the detection is wrong - the syscall will fail
and "hardlink" will become "False" again.


More information about the Mercurial-devel mailing list