obsolete: make sure windows tests pass when stat() is given a URL
This is a temporary fix for an issue that's only visible on windows, but exists
on other platforms as well.
The issue is if we're trying to use obsstore from a remote peer and that peer
is a static HTTP repo, vfs tries to os.stat() a remote file using a URL to that
file (e.g. http://localhost/repo/.hg/store/obsstore). The next patch in this
series makes branchcache obsolescence-aware, so in certain situations exchange
process will try os.stat()ing a URL. On windows this will produce an OSError
that is not ENOENT, but EINVAL instead (because of `:` symbol, for example).
Differential Revision: https://phab.mercurial-scm.org/D12100
# txnutil.py - transaction related utilities
#
# Copyright FUJIWARA Katsunori <foozy@lares.dti.ne.jp> and others
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import
import errno
from . import encoding
def mayhavepending(root):
"""return whether 'root' may have pending changes, which are
visible to this process.
"""
return root == encoding.environ.get(b'HG_PENDING')
def trypending(root, vfs, filename, **kwargs):
"""Open file to be read according to HG_PENDING environment variable
This opens '.pending' of specified 'filename' only when HG_PENDING
is equal to 'root'.
This returns '(fp, is_pending_opened)' tuple.
"""
if mayhavepending(root):
try:
return (vfs(b'%s.pending' % filename, **kwargs), True)
except IOError as inst:
if inst.errno != errno.ENOENT:
raise
return (vfs(filename, **kwargs), False)