[PATCH] util: add a getfstype method

Jun Wu quark at fb.com
Fri Mar 3 01:15:05 EST 2017


I went ahead implementing a test gated by a new hghave check. I'll drop this
from patchwork.

Excerpts from Jun Wu's message of 2017-03-02 16:58:30 -0800:
> Excerpts from Augie Fackler's message of 2017-03-02 19:58:14 -0500:
> > On Thu, Mar 02, 2017 at 11:22:16AM -0800, Jun Wu wrote:
> > > # HG changeset patch
> > > # User Jun Wu <quark at fb.com>
> > > # Date 1488482129 28800
> > > #      Thu Mar 02 11:15:29 2017 -0800
> > > # Node ID 1e0decacf511722da03e0297bd846b2379953ae6
> > > # Parent  0bb3089fe73527c64f1afc40b86ecb8dfe7fd7aa
> > > # Available At https://bitbucket.org/quark-zju/hg-draft  
> > > #              hg pull https://bitbucket.org/quark-zju/hg-draft   -r 1e0decacf511
> > > util: add a getfstype method
> > 
> > I'd really like to see this used in context before taking it, or at a
> > minimum a sketch of the full path forward (including some testing notions.)
> 
> The test is a bit hard to write - we cannot mount filesystem from userspace
> (in a portable way). So I guess the best thing we can do is probably testing
> equality for two paths that we are sure that they are on a same filesystem.
> 
> I'll try to get it used in vfs.
> 
> > 
> > Thanks!
> > 
> > >
> > > We have been very conservative about things like hardlink, flock etc.
> > > because of some buggy (network) filesystem implementations. That's sad
> > > because there are a lot of good (local) filesystem implementations where
> > > optimizations like hardlinks could be just used safely.
> > >
> > > This patch adds a "getfstype" method as a first step to solve the problem.
> > > It only supports Linux for now, as Linux is widely used and could be
> > > supported relatively cleanly. We can add support for other platforms later.
> > >
> > > diff --git a/mercurial/posix.py b/mercurial/posix.py
> > > --- a/mercurial/posix.py
> > > +++ b/mercurial/posix.py
> > > @@ -658,2 +658,33 @@ def bindunixsocket(sock, path):
> > >          os.fchdir(bakwdfd)
> > >          os.close(bakwdfd)
> > > +
> > > +if pycompat.sysplatform.startswith('linux'):
> > > +    # for Linux, reading /etc/mtab (symlink to /proc/self/mounts) is a reliable
> > > +    # way to get the current filesystem mount information
> > > +    def _fstypetable():
> > > +        result = {}
> > > +        try:
> > > +            with open('/etc/mtab', 'r') as f:
> > > +                for line in f.read().splitlines():
> > > +                    name, path, fs, ops, freq, passno = line.split(' ', 5)
> > > +                    result[path] = fs
> > > +        except OSError:
> > > +            # /etc/mtab is not guaranteed available
> > > +            pass
> > > +        return result
> > > +else:
> > > +    # unknown platform
> > > +    def _fstypetable():
> > > +        return {}
> > > +
> > > +def getfstype(path):
> > > +    """Given a path, return filesystem type or None (best-effort)"""
> > > +    table = _fstypetable()
> > > +    while True:
> > > +        if path in table:
> > > +            return table[path]
> > > +        nextpath = os.path.dirname(path)
> > > +        if nextpath == path:
> > > +            return None
> > > +        else:
> > > +            path = nextpath
> > > diff --git a/mercurial/util.py b/mercurial/util.py
> > > --- a/mercurial/util.py
> > > +++ b/mercurial/util.py
> > > @@ -93,7 +93,8 @@ expandglobs = platform.expandglobs
> > >  explainexit = platform.explainexit
> > >  findexe = platform.findexe
> > > +getfstype = platform.getfstype
> > >  gethgcmd = platform.gethgcmd
> > > +getpid = os.getpid
> > >  getuser = platform.getuser
> > > -getpid = os.getpid
> > >  groupmembers = platform.groupmembers
> > >  groupname = platform.groupname
> > > diff --git a/mercurial/windows.py b/mercurial/windows.py
> > > --- a/mercurial/windows.py
> > > +++ b/mercurial/windows.py
> > > @@ -478,2 +478,7 @@ def readpipe(pipe):
> > >  def bindunixsocket(sock, path):
> > >      raise NotImplementedError('unsupported platform')
> > > +
> > > +def getfstype(path):
> > > +    """Given a path, return filesystem type or None (best-effort)"""
> > > +    # not implemented for Windows
> > > +    return None
> > > _______________________________________________
> > > Mercurial-devel mailing list
> > > Mercurial-devel at mercurial-scm.org
> > > https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel  


More information about the Mercurial-devel mailing list