2009-08-05 16:42:57 +04:00
|
|
|
# lock.py - simple advisory locking scheme for mercurial
|
2005-05-26 20:53:04 +04:00
|
|
|
#
|
2006-08-12 23:30:02 +04:00
|
|
|
# Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
|
2005-05-26 20:53:04 +04:00
|
|
|
#
|
2009-04-26 03:08:54 +04:00
|
|
|
# This software may be used and distributed according to the terms of the
|
2010-01-20 07:20:08 +03:00
|
|
|
# GNU General Public License version 2 or any later version.
|
2005-05-26 20:53:04 +04:00
|
|
|
|
2015-08-09 05:30:17 +03:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2015-10-05 06:02:50 +03:00
|
|
|
import contextlib
|
2015-08-09 05:30:17 +03:00
|
|
|
import errno
|
2017-02-11 00:56:31 +03:00
|
|
|
import os
|
2015-08-09 05:30:17 +03:00
|
|
|
import socket
|
|
|
|
import time
|
2009-04-22 04:01:22 +04:00
|
|
|
import warnings
|
2005-05-26 20:53:04 +04:00
|
|
|
|
2018-07-23 13:51:10 +03:00
|
|
|
from . import encoding, error, progress, pycompat, util
|
2017-11-30 04:36:29 +03:00
|
|
|
from .i18n import _
|
|
|
|
|
2015-08-09 05:30:17 +03:00
|
|
|
|
2018-04-10 13:59:04 +03:00
|
|
|
if pycompat.iswindows:
|
|
|
|
from . import win32
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2018-08-09 02:07:23 +03:00
|
|
|
class _emptylockinfo(object):
|
2018-04-10 13:59:02 +03:00
|
|
|
def getwarning(self, l):
|
|
|
|
return _("waiting for lock on %r") % l.desc
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
|
|
|
|
2018-08-09 02:07:23 +03:00
|
|
|
emptylockinfo = _emptylockinfo()
|
2017-02-11 00:35:21 +03:00
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2018-08-09 02:07:23 +03:00
|
|
|
class lockinfo(object):
|
|
|
|
"""Information about who is holding the lock.
|
2018-04-10 13:59:02 +03:00
|
|
|
|
2018-08-09 02:07:23 +03:00
|
|
|
Does not have write side-effect (ex. take or release a lock).
|
2017-02-11 00:35:21 +03:00
|
|
|
"""
|
2018-05-30 12:16:33 +03:00
|
|
|
|
2018-04-10 13:59:02 +03:00
|
|
|
_currentnamespace = None
|
|
|
|
|
2018-04-16 21:54:04 +03:00
|
|
|
def __init__(self, fromstr, path=None):
|
2018-08-09 02:07:23 +03:00
|
|
|
"""
|
|
|
|
fromstr := namespace + ":" + identification
|
|
|
|
namespace := hostname (non-Linux) | hostname + "/" + pid-namespace (Linux)
|
|
|
|
identification := pid (non-Windows) | pid + "/" + starttime (Windows)
|
|
|
|
"""
|
2018-04-10 13:59:02 +03:00
|
|
|
self.pidnamespace = None
|
|
|
|
self.host = None
|
|
|
|
self.pid = None
|
2018-04-10 13:59:04 +03:00
|
|
|
self.starttime = None
|
2018-04-10 13:59:02 +03:00
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
if ":" not in fromstr:
|
|
|
|
msg = _("malformed lock file")
|
|
|
|
hint = ""
|
2018-04-16 21:54:04 +03:00
|
|
|
if path is not None:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
msg += " (%s)" % path
|
|
|
|
hint = _("run hg debuglocks")
|
2018-04-16 21:54:04 +03:00
|
|
|
raise error.MalformedLock(msg, hint=hint)
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
ns, uid = fromstr.strip().split(":", 1)
|
2018-04-10 13:59:02 +03:00
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
if "/" in ns:
|
|
|
|
self.host, self.pidnamespace = ns.split("/", 1)
|
2018-04-10 13:59:02 +03:00
|
|
|
elif ns:
|
|
|
|
self.host = ns
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
if uid and "/" in uid:
|
|
|
|
self.pid, self.starttime = uid.split("/", 2)
|
2018-04-10 13:59:04 +03:00
|
|
|
else:
|
|
|
|
self.pid = uid
|
2018-04-10 13:59:02 +03:00
|
|
|
|
|
|
|
def __eq__(self, other):
|
2018-08-09 02:07:23 +03:00
|
|
|
if other is None or other == emptylockinfo:
|
2018-04-10 13:59:02 +03:00
|
|
|
return False
|
|
|
|
if isinstance(other, str):
|
2018-08-09 02:07:23 +03:00
|
|
|
return self == lockinfo(other)
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
return self.namespace == other.namespace and self.uniqueid == other.uniqueid
|
2018-04-10 13:59:02 +03:00
|
|
|
|
|
|
|
@property
|
|
|
|
def namespace(self):
|
|
|
|
if self.pidnamespace:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
return self.host + "/" + self.pidnamespace
|
2018-04-10 13:59:02 +03:00
|
|
|
return self.host
|
|
|
|
|
|
|
|
@property
|
|
|
|
def uniqueid(self):
|
2018-04-10 13:59:04 +03:00
|
|
|
if self.starttime is not None:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
return self.pid + "/" + self.starttime
|
2018-04-10 13:59:02 +03:00
|
|
|
return self.pid
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def getcurrentnamespace(cls):
|
|
|
|
if cls._currentnamespace is not None:
|
|
|
|
return cls._currentnamespace
|
|
|
|
result = socket.gethostname()
|
|
|
|
if pycompat.ispy3:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
result = result.encode(pycompat.sysstr(encoding.encoding), "replace")
|
|
|
|
if pycompat.sysplatform.startswith("linux"):
|
2018-04-10 13:59:02 +03:00
|
|
|
try:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
result += "/%x" % os.stat("/proc/self/ns/pid").st_ino
|
2018-04-10 13:59:02 +03:00
|
|
|
except OSError as ex:
|
|
|
|
if ex.errno not in (errno.ENOENT, errno.EACCES, errno.ENOTDIR):
|
|
|
|
raise
|
|
|
|
cls._currentnamespace = result
|
|
|
|
return result
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def getcurrentid():
|
2018-04-10 13:59:04 +03:00
|
|
|
if pycompat.iswindows:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
return "%d/%d" % (util.getpid(), win32.getcurrentprocstarttime())
|
2018-04-10 13:59:02 +03:00
|
|
|
return str(util.getpid())
|
|
|
|
|
|
|
|
def issamenamespace(self):
|
2018-08-09 02:07:23 +03:00
|
|
|
"""Check if the current process is in the same namespace as lockinfo"""
|
2018-04-10 13:59:02 +03:00
|
|
|
return self.namespace == self.getcurrentnamespace()
|
|
|
|
|
|
|
|
def isrunning(self):
|
2018-08-09 02:07:23 +03:00
|
|
|
"""Check if locker process is still running"""
|
2018-04-10 13:59:04 +03:00
|
|
|
if self.pid is None:
|
|
|
|
return False
|
|
|
|
pid = int(self.pid)
|
|
|
|
starttime = self.starttime and int(self.starttime)
|
|
|
|
result = util.testpid(pid)
|
|
|
|
if result and pycompat.iswindows and starttime is not None:
|
|
|
|
result = starttime == win32.getprocstarttime(pid)
|
|
|
|
return result
|
2018-04-10 13:59:02 +03:00
|
|
|
|
|
|
|
def getwarning(self, l):
|
2018-08-09 02:07:23 +03:00
|
|
|
"""Get a lockinfo's warning string while trying to acquire `l` lock"""
|
2018-04-10 13:59:02 +03:00
|
|
|
msg = _("waiting for lock on %s held by process %r on host %r\n")
|
|
|
|
msg %= (l.desc, self.pid, self.host)
|
2018-08-23 07:26:50 +03:00
|
|
|
hintmsg = _(
|
|
|
|
"(hint: run 'hg debugprocesstree %s' to see related processes)\n"
|
|
|
|
) % (self.pid,)
|
|
|
|
return msg + hintmsg
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2017-02-11 00:35:21 +03:00
|
|
|
|
2017-11-30 04:39:59 +03:00
|
|
|
def trylock(ui, vfs, lockname, timeout, warntimeout, *args, **kwargs):
|
2017-11-30 04:36:29 +03:00
|
|
|
"""return an acquired lock or raise an a LockHeld exception
|
|
|
|
|
2017-11-30 04:39:59 +03:00
|
|
|
This function is responsible to issue warnings and or debug messages about
|
|
|
|
the held lock while trying to acquires it."""
|
2018-04-10 13:59:06 +03:00
|
|
|
l = lock(vfs, lockname, 0, *args, dolock=False, ui=ui, **kwargs)
|
2017-11-30 04:36:29 +03:00
|
|
|
|
2017-11-30 04:39:59 +03:00
|
|
|
debugidx = 0 if (warntimeout and timeout) else -1
|
2017-11-30 04:36:29 +03:00
|
|
|
warningidx = 0
|
|
|
|
if not timeout:
|
|
|
|
warningidx = -1
|
2017-11-30 04:39:59 +03:00
|
|
|
elif warntimeout:
|
|
|
|
warningidx = warntimeout
|
2017-11-30 04:36:29 +03:00
|
|
|
|
|
|
|
delay = 0
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
l._trylock()
|
|
|
|
break
|
|
|
|
except error.LockHeld as inst:
|
2017-11-30 04:39:59 +03:00
|
|
|
if delay == debugidx:
|
2018-08-09 02:07:23 +03:00
|
|
|
ui.debug(inst.lockinfo.getwarning(l))
|
2017-11-30 04:36:29 +03:00
|
|
|
if delay == warningidx:
|
2018-08-09 02:07:23 +03:00
|
|
|
ui.warn(inst.lockinfo.getwarning(l))
|
2017-11-30 04:36:29 +03:00
|
|
|
if timeout <= delay:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
raise error.LockHeld(
|
2018-08-09 02:07:23 +03:00
|
|
|
errno.ETIMEDOUT, inst.filename, l.desc, inst.lockinfo
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
)
|
2017-11-30 04:36:29 +03:00
|
|
|
time.sleep(1)
|
|
|
|
delay += 1
|
|
|
|
|
|
|
|
l.delay = delay
|
|
|
|
if l.delay:
|
2018-04-10 13:59:02 +03:00
|
|
|
msg = _("got lock after %s seconds\n") % l.delay
|
2017-11-30 04:39:59 +03:00
|
|
|
if 0 <= warningidx <= l.delay:
|
2018-04-10 13:59:02 +03:00
|
|
|
ui.warn(msg)
|
2017-11-30 04:39:59 +03:00
|
|
|
else:
|
2018-04-10 13:59:02 +03:00
|
|
|
ui.debug(msg)
|
2017-11-30 04:36:29 +03:00
|
|
|
if l.acquirefn:
|
|
|
|
l.acquirefn()
|
|
|
|
return l
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2005-11-19 09:48:47 +03:00
|
|
|
class lock(object):
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
"""An advisory lock held by one process to control access to a set
|
2009-08-05 16:42:57 +04:00
|
|
|
of files. Non-cooperating processes or incorrectly written scripts
|
|
|
|
can ignore Mercurial's locking scheme and stomp all over the
|
|
|
|
repository, so don't do that.
|
|
|
|
|
|
|
|
Typically used via localrepository.lock() to lock the repository
|
|
|
|
store (.hg/store/) or localrepository.wlock() to lock everything
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
else under .hg/."""
|
2009-08-05 16:42:57 +04:00
|
|
|
|
2006-03-10 19:31:31 +03:00
|
|
|
# lock is symlink on platforms that support it, file on others.
|
|
|
|
|
|
|
|
# symlink is used because create of directory entry and contents
|
|
|
|
# are atomic even over nfs.
|
|
|
|
|
|
|
|
# old-style lock: symlink to pid
|
|
|
|
# new-style lock: symlink to hostname:pid
|
|
|
|
|
2018-04-10 13:59:02 +03:00
|
|
|
_namespace = None
|
2007-07-20 02:13:48 +04:00
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
vfs,
|
|
|
|
file,
|
|
|
|
timeout=-1,
|
|
|
|
releasefn=None,
|
|
|
|
acquirefn=None,
|
|
|
|
desc=None,
|
|
|
|
inheritchecker=None,
|
|
|
|
parentlock=None,
|
|
|
|
dolock=True,
|
|
|
|
ui=None,
|
2018-07-23 13:51:10 +03:00
|
|
|
showspinner=False,
|
|
|
|
spinnermsg=None,
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
):
|
2013-11-12 11:23:52 +04:00
|
|
|
self.vfs = vfs
|
2005-05-26 20:53:04 +04:00
|
|
|
self.f = file
|
|
|
|
self.held = 0
|
2006-02-22 01:21:15 +03:00
|
|
|
self.timeout = timeout
|
2005-11-12 02:34:09 +03:00
|
|
|
self.releasefn = releasefn
|
2015-09-23 00:09:42 +03:00
|
|
|
self.acquirefn = acquirefn
|
2006-03-28 21:01:07 +04:00
|
|
|
self.desc = desc
|
2015-10-06 23:13:31 +03:00
|
|
|
self._inheritchecker = inheritchecker
|
2015-09-25 01:57:11 +03:00
|
|
|
self.parentlock = parentlock
|
|
|
|
self._parentheld = False
|
|
|
|
self._inherited = False
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
self.postrelease = []
|
2015-09-25 07:26:37 +03:00
|
|
|
self.pid = self._getpid()
|
2018-04-10 13:59:06 +03:00
|
|
|
self.ui = ui
|
2018-07-23 13:51:10 +03:00
|
|
|
self.showspinner = showspinner
|
|
|
|
self.spinnermsg = spinnermsg
|
|
|
|
self._debugmessagesprinted = set([])
|
2018-08-09 02:07:25 +03:00
|
|
|
self._lockfd = None
|
2017-11-30 04:36:29 +03:00
|
|
|
if dolock:
|
|
|
|
self.delay = self.lock()
|
|
|
|
if self.acquirefn:
|
|
|
|
self.acquirefn()
|
2005-05-26 20:53:04 +04:00
|
|
|
|
2016-01-16 00:14:45 +03:00
|
|
|
def __enter__(self):
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __exit__(self, exc_type, exc_value, exc_tb):
|
|
|
|
self.release()
|
|
|
|
|
2005-05-26 20:53:04 +04:00
|
|
|
def __del__(self):
|
2009-04-22 04:01:22 +04:00
|
|
|
if self.held:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
warnings.warn(
|
|
|
|
"use lock.release instead of del lock",
|
|
|
|
category=DeprecationWarning,
|
|
|
|
stacklevel=2,
|
|
|
|
)
|
2009-04-22 04:01:22 +04:00
|
|
|
|
2009-04-22 04:01:22 +04:00
|
|
|
# ensure the lock will be removed
|
|
|
|
# even if recursive locking did occur
|
|
|
|
self.held = 1
|
|
|
|
|
2005-05-26 20:53:04 +04:00
|
|
|
self.release()
|
|
|
|
|
2015-09-25 07:26:37 +03:00
|
|
|
def _getpid(self):
|
2018-08-09 02:07:23 +03:00
|
|
|
# wrapper around lockinfo.getcurrentid() to make testing easier
|
|
|
|
return lockinfo.getcurrentid()
|
2018-04-10 13:59:02 +03:00
|
|
|
|
|
|
|
def _getlockname(self):
|
2018-08-09 02:07:23 +03:00
|
|
|
return "%s:%s" % (lockinfo.getcurrentnamespace(), self.pid)
|
2015-09-25 07:26:37 +03:00
|
|
|
|
2005-05-26 20:53:04 +04:00
|
|
|
def lock(self):
|
2018-07-23 13:51:10 +03:00
|
|
|
# wrapper around locking to show spinner
|
|
|
|
if self.showspinner and self.ui:
|
|
|
|
if self.spinnermsg:
|
|
|
|
msg = self.spinnermsg
|
|
|
|
else:
|
|
|
|
msg = _("waiting for the lock to be released")
|
|
|
|
spinner = progress.spinner(self.ui, msg)
|
|
|
|
else:
|
|
|
|
spinner = util.nullcontextmanager()
|
|
|
|
with spinner:
|
|
|
|
self._dolock()
|
|
|
|
|
|
|
|
def _dolock(self):
|
2006-02-22 01:21:15 +03:00
|
|
|
timeout = self.timeout
|
2011-06-01 14:38:46 +04:00
|
|
|
while True:
|
2005-05-26 20:53:04 +04:00
|
|
|
try:
|
2015-08-24 21:26:10 +03:00
|
|
|
self._trylock()
|
2014-02-06 04:55:09 +04:00
|
|
|
return self.timeout - timeout
|
2015-06-24 08:20:08 +03:00
|
|
|
except error.LockHeld as inst:
|
2006-02-22 01:21:15 +03:00
|
|
|
if timeout != 0:
|
2005-05-26 20:53:04 +04:00
|
|
|
time.sleep(1)
|
2006-02-22 01:21:15 +03:00
|
|
|
if timeout > 0:
|
|
|
|
timeout -= 1
|
2005-05-26 20:53:04 +04:00
|
|
|
continue
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
raise error.LockHeld(
|
2018-08-09 02:07:23 +03:00
|
|
|
errno.ETIMEDOUT, inst.filename, self.desc, inst.lockinfo
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
)
|
2005-06-29 22:42:35 +04:00
|
|
|
|
2015-08-24 21:26:10 +03:00
|
|
|
def _trylock(self):
|
2009-04-22 04:01:22 +04:00
|
|
|
if self.held:
|
|
|
|
self.held += 1
|
|
|
|
return
|
2018-08-09 02:07:25 +03:00
|
|
|
assert self._lockfd is None
|
2015-08-24 21:24:43 +03:00
|
|
|
retry = 5
|
|
|
|
while not self.held and retry:
|
|
|
|
retry -= 1
|
2006-03-10 19:31:31 +03:00
|
|
|
try:
|
2018-08-09 02:07:25 +03:00
|
|
|
self._lockfd = self.vfs.makelock(self._getlockname(), self.f)
|
2006-03-10 19:31:31 +03:00
|
|
|
self.held = 1
|
2015-06-24 08:20:08 +03:00
|
|
|
except (OSError, IOError) as why:
|
2018-08-09 02:07:25 +03:00
|
|
|
# EEXIST: lockfile exists (Windows)
|
|
|
|
# ELOOP: lockfile exists as a symlink (POSIX)
|
|
|
|
# EAGAIN: lockfile flock taken by other process (POSIX)
|
|
|
|
if why.errno in {errno.EEXIST, errno.ELOOP, errno.EAGAIN}:
|
2018-04-10 13:59:02 +03:00
|
|
|
lockfilecontents = self._readlock()
|
|
|
|
if lockfilecontents is None:
|
lock: avoid unintentional lock acquisition at failure of readlock
Acquiring lock by vfs.makelock() and getting lock holder (aka
"locker") information by vfs.readlock() aren't atomic action.
Therefore, failure of the former doesn't ensure success of the latter.
Before this patch, lock is unintentionally acquired, if
self.parentlock is None (this is default value), and lock._readlock()
returns None for ENOENT at vfs.readlock(), because these None are
recognized as equal to each other.
In this case, lock symlink (or file) isn't created, even though lock
is treated as acquired in memory.
To avoid this issue, this patch retries lock acquisition immediately,
if lock._readlock() returns None "locker".
This issue will be covered by a test added in subsequent patch,
because simple emulation of ENOENT at vfs.readlock() easily causes
another issue. "raising ENOENT only at the first vfs.readlock()
invocation" is too complicated for unit test, IMHO.
2017-05-01 13:58:52 +03:00
|
|
|
continue
|
2018-08-09 02:07:23 +03:00
|
|
|
info = lockinfo(lockfilecontents, path=self.vfs.join(self.f))
|
lock: avoid unintentional lock acquisition at failure of readlock
Acquiring lock by vfs.makelock() and getting lock holder (aka
"locker") information by vfs.readlock() aren't atomic action.
Therefore, failure of the former doesn't ensure success of the latter.
Before this patch, lock is unintentionally acquired, if
self.parentlock is None (this is default value), and lock._readlock()
returns None for ENOENT at vfs.readlock(), because these None are
recognized as equal to each other.
In this case, lock symlink (or file) isn't created, even though lock
is treated as acquired in memory.
To avoid this issue, this patch retries lock acquisition immediately,
if lock._readlock() returns None "locker".
This issue will be covered by a test added in subsequent patch,
because simple emulation of ENOENT at vfs.readlock() easily causes
another issue. "raising ENOENT only at the first vfs.readlock()
invocation" is too complicated for unit test, IMHO.
2017-05-01 13:58:52 +03:00
|
|
|
|
2015-09-25 08:07:55 +03:00
|
|
|
# special case where a parent process holds the lock -- this
|
|
|
|
# is different from the pid being different because we do
|
|
|
|
# want the unlock and postrelease functions to be called,
|
|
|
|
# but the lockfile to not be removed.
|
2018-08-09 02:07:23 +03:00
|
|
|
if info == self.parentlock:
|
2015-09-25 08:07:55 +03:00
|
|
|
self._parentheld = True
|
|
|
|
self.held = 1
|
|
|
|
return
|
2018-08-09 02:07:23 +03:00
|
|
|
info = self._testlock(info)
|
|
|
|
if info is not None:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
raise error.LockHeld(
|
2018-08-09 02:07:23 +03:00
|
|
|
errno.EAGAIN, self.vfs.join(self.f), self.desc, info
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
)
|
2018-08-09 02:07:25 +03:00
|
|
|
|
2006-03-10 19:31:31 +03:00
|
|
|
else:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
raise error.LockUnavailable(
|
|
|
|
why.errno, why.strerror, why.filename, self.desc
|
|
|
|
)
|
2006-03-10 19:31:31 +03:00
|
|
|
|
lock: avoid unintentional lock acquisition at failure of readlock
Acquiring lock by vfs.makelock() and getting lock holder (aka
"locker") information by vfs.readlock() aren't atomic action.
Therefore, failure of the former doesn't ensure success of the latter.
Before this patch, lock is unintentionally acquired, if ENOENT
causes failure of vfs.readlock() while 5 times retrying, because
lock._trylock() returns to caller silently after retrying, and
lock.lock() assumes that lock._trylock() returns successfully only if
lock is acquired.
In this case, lock symlink (or file) isn't created, even though lock
is treated as acquired in memory.
To avoid this issue, this patch makes lock._trylock() raise
LockHeld(EAGAIN) at the end of it, if lock isn't acquired while
retrying.
An empty "locker" meaning "busy for frequent lock/unlock by many
processes" might appear in an abortion message, if lock acquisition
fails. Therefore, this patch also does:
- use '%r' to increase visibility of "locker", even if it is empty
- show hint message to explain what empty "locker" means
2017-05-01 13:59:13 +03:00
|
|
|
if not self.held:
|
2018-08-09 02:07:23 +03:00
|
|
|
# use empty lockinfo to mean "busy for frequent lock/unlock
|
lock: avoid unintentional lock acquisition at failure of readlock
Acquiring lock by vfs.makelock() and getting lock holder (aka
"locker") information by vfs.readlock() aren't atomic action.
Therefore, failure of the former doesn't ensure success of the latter.
Before this patch, lock is unintentionally acquired, if ENOENT
causes failure of vfs.readlock() while 5 times retrying, because
lock._trylock() returns to caller silently after retrying, and
lock.lock() assumes that lock._trylock() returns successfully only if
lock is acquired.
In this case, lock symlink (or file) isn't created, even though lock
is treated as acquired in memory.
To avoid this issue, this patch makes lock._trylock() raise
LockHeld(EAGAIN) at the end of it, if lock isn't acquired while
retrying.
An empty "locker" meaning "busy for frequent lock/unlock by many
processes" might appear in an abortion message, if lock acquisition
fails. Therefore, this patch also does:
- use '%r' to increase visibility of "locker", even if it is empty
- show hint message to explain what empty "locker" means
2017-05-01 13:59:13 +03:00
|
|
|
# by many processes"
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
raise error.LockHeld(
|
2018-08-09 02:07:23 +03:00
|
|
|
errno.EAGAIN, self.vfs.join(self.f), self.desc, emptylockinfo
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
)
|
lock: avoid unintentional lock acquisition at failure of readlock
Acquiring lock by vfs.makelock() and getting lock holder (aka
"locker") information by vfs.readlock() aren't atomic action.
Therefore, failure of the former doesn't ensure success of the latter.
Before this patch, lock is unintentionally acquired, if ENOENT
causes failure of vfs.readlock() while 5 times retrying, because
lock._trylock() returns to caller silently after retrying, and
lock.lock() assumes that lock._trylock() returns successfully only if
lock is acquired.
In this case, lock symlink (or file) isn't created, even though lock
is treated as acquired in memory.
To avoid this issue, this patch makes lock._trylock() raise
LockHeld(EAGAIN) at the end of it, if lock isn't acquired while
retrying.
An empty "locker" meaning "busy for frequent lock/unlock by many
processes" might appear in an abortion message, if lock acquisition
fails. Therefore, this patch also does:
- use '%r' to increase visibility of "locker", even if it is empty
- show hint message to explain what empty "locker" means
2017-05-01 13:59:13 +03:00
|
|
|
|
2015-09-17 05:26:59 +03:00
|
|
|
def _readlock(self):
|
|
|
|
"""read lock and return its value
|
|
|
|
|
|
|
|
Returns None if no lock exists, pid for old-style locks, and host:pid
|
|
|
|
for new-style locks.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
return self.vfs.readlock(self.f)
|
|
|
|
except (OSError, IOError) as why:
|
|
|
|
if why.errno == errno.ENOENT:
|
|
|
|
return None
|
|
|
|
raise
|
|
|
|
|
2018-04-10 13:59:06 +03:00
|
|
|
def _debugprintonce(self, msg):
|
|
|
|
"""Print debug message only once"""
|
|
|
|
if not self.ui or msg in self._debugmessagesprinted:
|
|
|
|
return
|
|
|
|
self._debugmessagesprinted.add(msg)
|
|
|
|
self.ui.debug(msg)
|
|
|
|
|
2018-08-09 02:07:23 +03:00
|
|
|
def _testlock(self, info):
|
|
|
|
if info is None:
|
2015-09-17 05:26:59 +03:00
|
|
|
return None
|
2018-08-09 02:07:23 +03:00
|
|
|
if not info.issamenamespace():
|
2018-04-10 13:59:06 +03:00
|
|
|
# this and below debug prints will hopefully help us
|
|
|
|
# understand the issue with stale lock files not being
|
|
|
|
# cleaned up on Windows (T25415269)
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
m = _("locker is not in the same namespace(locker: %r, us: %r)\n")
|
2018-08-09 02:07:23 +03:00
|
|
|
m %= (info.namespace, lockinfo.getcurrentnamespace())
|
2018-04-10 13:59:06 +03:00
|
|
|
self._debugprintonce(m)
|
2018-08-09 02:07:23 +03:00
|
|
|
return info
|
2018-09-13 22:09:31 +03:00
|
|
|
# On posix.makelock removes stale locks automatically. So there is no
|
|
|
|
# need to remove stale lock here.
|
|
|
|
if info.isrunning() or not pycompat.iswindows:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
m = _("locker is still running (full unique id: %r)\n")
|
2018-08-09 02:07:23 +03:00
|
|
|
m %= (info.uniqueid,)
|
2018-04-10 13:59:06 +03:00
|
|
|
self._debugprintonce(m)
|
2018-08-09 02:07:23 +03:00
|
|
|
return info
|
2018-09-13 22:09:31 +03:00
|
|
|
# XXX: The below logic is broken since "read + test + unlink" should
|
|
|
|
# happen atomically, in a same critical section. Use another lock to
|
|
|
|
# only protect "unlink" is not enough.
|
|
|
|
#
|
2018-08-09 02:07:23 +03:00
|
|
|
# if lockinfo dead, break lock. must do this with another lock
|
2006-03-10 19:31:31 +03:00
|
|
|
# held, or can race and break valid lock.
|
2005-05-26 20:53:04 +04:00
|
|
|
try:
|
2018-08-09 02:07:25 +03:00
|
|
|
# The "remove dead lock" logic is done by posix.makelock, not here.
|
2018-09-13 22:09:31 +03:00
|
|
|
assert pycompat.iswindows
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
msg = _(
|
|
|
|
"trying to removed the stale lock file " "(will acquire %s for that)\n"
|
|
|
|
)
|
|
|
|
breaklock = self.f + ".break"
|
2018-04-11 12:38:24 +03:00
|
|
|
self._debugprintonce(msg % breaklock)
|
|
|
|
l = lock(self.vfs, breaklock, timeout=0)
|
2013-11-12 11:23:52 +04:00
|
|
|
self.vfs.unlink(self.f)
|
2006-03-10 19:31:31 +03:00
|
|
|
l.release()
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
self._debugprintonce(_("removed the stale lock file\n"))
|
2018-08-21 19:43:48 +03:00
|
|
|
except error.LockError:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
self._debugprintonce(_("failed to remove the stale lock file\n"))
|
2018-08-09 02:07:23 +03:00
|
|
|
return info
|
2005-05-26 20:53:04 +04:00
|
|
|
|
2015-09-17 05:52:06 +03:00
|
|
|
def testlock(self):
|
2018-08-09 02:07:23 +03:00
|
|
|
"""return id of lockinfo if lock is valid, else None.
|
2015-09-17 05:52:06 +03:00
|
|
|
|
2018-08-09 02:07:23 +03:00
|
|
|
If old-style lock, we cannot tell what machine lockinfo is on.
|
|
|
|
with new-style lock, if lockinfo is on this machine, we can
|
|
|
|
see if lockinfo is alive. If lockinfo is on this machine but
|
2015-09-17 05:52:06 +03:00
|
|
|
not alive, we can safely break lock.
|
|
|
|
|
|
|
|
The lock file is only deleted when None is returned.
|
|
|
|
|
|
|
|
"""
|
2018-08-09 02:07:23 +03:00
|
|
|
info = lockinfo(self._readlock(), path=self.vfs.join(self.f))
|
|
|
|
return self._testlock(info)
|
2015-09-17 05:52:06 +03:00
|
|
|
|
2015-10-05 06:02:50 +03:00
|
|
|
@contextlib.contextmanager
|
|
|
|
def inherit(self):
|
|
|
|
"""context for the lock to be inherited by a Mercurial subprocess.
|
2015-09-24 20:37:13 +03:00
|
|
|
|
2015-10-05 06:02:50 +03:00
|
|
|
Yields a string that will be recognized by the lock in the subprocess.
|
|
|
|
Communicating this string to the subprocess needs to be done separately
|
|
|
|
-- typically by an environment variable.
|
2015-09-24 20:37:13 +03:00
|
|
|
"""
|
|
|
|
if not self.held:
|
|
|
|
raise error.LockInheritanceContractViolation(
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
"inherit can only be called while lock is held"
|
|
|
|
)
|
2015-09-24 20:37:13 +03:00
|
|
|
if self._inherited:
|
|
|
|
raise error.LockInheritanceContractViolation(
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
"inherit cannot be called while lock is already inherited"
|
|
|
|
)
|
2015-10-06 23:13:31 +03:00
|
|
|
if self._inheritchecker is not None:
|
|
|
|
self._inheritchecker()
|
2015-09-24 20:37:13 +03:00
|
|
|
if self.releasefn:
|
|
|
|
self.releasefn()
|
|
|
|
if self._parentheld:
|
|
|
|
lockname = self.parentlock
|
|
|
|
else:
|
2018-04-10 13:59:02 +03:00
|
|
|
lockname = self._getlockname()
|
2015-09-24 20:37:13 +03:00
|
|
|
self._inherited = True
|
2015-10-05 06:02:50 +03:00
|
|
|
try:
|
|
|
|
yield lockname
|
|
|
|
finally:
|
|
|
|
if self.acquirefn:
|
|
|
|
self.acquirefn()
|
|
|
|
self._inherited = False
|
2015-09-25 02:00:41 +03:00
|
|
|
|
2005-05-26 20:53:04 +04:00
|
|
|
def release(self):
|
2011-11-28 18:05:26 +04:00
|
|
|
"""release the lock and execute callback function if any
|
|
|
|
|
2012-09-11 19:36:09 +04:00
|
|
|
If the lock has been acquired multiple times, the actual release is
|
2012-08-16 00:38:42 +04:00
|
|
|
delayed to the last release call."""
|
2009-04-22 04:01:22 +04:00
|
|
|
if self.held > 1:
|
|
|
|
self.held -= 1
|
2009-10-31 19:07:12 +03:00
|
|
|
elif self.held == 1:
|
2005-05-26 20:53:04 +04:00
|
|
|
self.held = 0
|
2015-09-25 07:26:37 +03:00
|
|
|
if self._getpid() != self.pid:
|
2013-04-12 00:30:27 +04:00
|
|
|
# we forked, and are not the parent
|
|
|
|
return
|
2005-06-28 14:08:14 +04:00
|
|
|
try:
|
2014-10-17 06:15:51 +04:00
|
|
|
if self.releasefn:
|
|
|
|
self.releasefn()
|
|
|
|
finally:
|
2015-09-25 02:03:26 +03:00
|
|
|
if not self._parentheld:
|
|
|
|
try:
|
2018-09-05 04:56:29 +03:00
|
|
|
util.releaselock(self._lockfd, self.vfs.join(self.f))
|
|
|
|
self._lockfd = None
|
2015-09-25 02:03:26 +03:00
|
|
|
except OSError:
|
|
|
|
pass
|
2015-10-05 06:04:44 +03:00
|
|
|
# The postrelease functions typically assume the lock is not held
|
|
|
|
# at all.
|
|
|
|
if not self._parentheld:
|
|
|
|
for callback in self.postrelease:
|
|
|
|
callback()
|
2016-04-16 19:00:15 +03:00
|
|
|
# Prevent double usage and help clear cycles.
|
|
|
|
self.postrelease = None
|
2005-05-26 20:53:04 +04:00
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2009-04-22 04:01:22 +04:00
|
|
|
def release(*locks):
|
|
|
|
for lock in locks:
|
|
|
|
if lock is not None:
|
|
|
|
lock.release()
|