vfs: create copy at renaming to avoid file stat ambiguity if needed
In order to fix
issue5418,
bff5ccbe5ead made vfs.rename(checkambig=True)
omit advancing mtime of renamed file, if renamed file is owned by
another (EPERM is raised in this case).
But this omission causes rewinding mtime at restoration in such
situation, and makes avoiding file stat ambiguity difficult, because
ExactCacheValidationPlan assumes that mtime should be advanced, if a
file is changed in same ctime.
https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan
Ambiguity of file stat also requires
issue5584 to be fixed with other
than file stat, but "hash of file", "generation ID" and so on were
already rejected ideas (please see original RFC linked from "Outline
of issue" in ExactCacheValidationPlan page).
This omission occurs:
- only for non append-only files (dirstate, bookmarks, and phaseroots), and
- only if previous transaction is rollbacked by another user
The latter means "sharing a repository clone via group permission".
This is reasonable usecase, but not ordinary for many users, IMHO.
"hg rollback" itself has been deprecated since Mercurial 2.7, too.
Therefore, increasing the cost at rollbacking previous transaction
executed by another a little seems reasonable, for avoidance of file
stat ambiguity.
This patch does:
- create copy of (already renamed) source file, if advancing mtime
fails for EPERM
- rename from copied file to destination file, and
- advance mtime of renamed file, which is now owned by current user
This patch also factors "self.join(src)" out to reduce redundancy.
# hgdemandimport - global demand-loading of modules for Mercurial
#
# Copyright 2017 Facebook Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
'''demandimport - automatic demand-loading of modules'''
# This is in a separate package from mercurial because in Python 3,
# demand loading is per-package. Keeping demandimport in the mercurial package
# would disable demand loading for any modules in mercurial.
from __future__ import absolute_import
import sys
if sys.version_info[0] >= 3:
from . import demandimportpy3 as demandimport
else:
from . import demandimportpy2 as demandimport
# Extensions can add to this list if necessary.
ignore = [
'__future__',
'_hashlib',
# ImportError during pkg_resources/__init__.py:fixup_namespace_package
'_imp',
'_xmlplus',
'fcntl',
'nt', # pathlib2 tests the existence of built-in 'nt' module
'win32com.gen_py',
'win32com.shell', # 'appdirs' tries to import win32com.shell
'_winreg', # 2.7 mimetypes needs immediate ImportError
'pythoncom',
# imported by tarfile, not available under Windows
'pwd',
'grp',
# imported by profile, itself imported by hotshot.stats,
# not available under Windows
'resource',
# this trips up many extension authors
'gtk',
# setuptools' pkg_resources.py expects "from __main__ import x" to
# raise ImportError if x not defined
'__main__',
'_ssl', # conditional imports in the stdlib, issue1964
'_sre', # issue4920
'rfc822',
'mimetools',
'sqlalchemy.events', # has import-time side effects (issue5085)
# setuptools 8 expects this module to explode early when not on windows
'distutils.msvc9compiler',
'__builtin__',
'builtins',
'urwid.command_map', # for pudb
]
_pypy = '__pypy__' in sys.builtin_module_names
if _pypy:
ignore.extend([
# _ctypes.pointer is shadowed by "from ... import pointer" (PyPy 5)
'_ctypes.pointer',
])
demandimport.init(ignore)
# Re-export.
isenabled = demandimport.isenabled
enable = demandimport.enable
disable = demandimport.disable
deactivated = demandimport.deactivated