2009-04-26 03:13:08 +04:00
|
|
|
# posix.py - Posix utility function implementations for Mercurial
|
|
|
|
#
|
|
|
|
# Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others
|
|
|
|
#
|
|
|
|
# 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.
|
2009-03-26 21:54:44 +03:00
|
|
|
|
2015-08-09 05:56:58 +03:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2018-08-09 02:07:25 +03:00
|
|
|
import contextlib
|
2015-08-09 05:56:58 +03:00
|
|
|
import errno
|
|
|
|
import fcntl
|
|
|
|
import getpass
|
|
|
|
import grp
|
|
|
|
import os
|
|
|
|
import pwd
|
|
|
|
import re
|
2018-06-07 21:24:38 +03:00
|
|
|
import resource
|
2015-05-21 02:00:05 +03:00
|
|
|
import select
|
2015-08-09 05:56:58 +03:00
|
|
|
import stat
|
|
|
|
import sys
|
|
|
|
import tempfile
|
|
|
|
import unicodedata
|
|
|
|
|
2018-10-23 18:25:50 +03:00
|
|
|
from . import encoding, error, executionmodel, fscap, pycompat
|
2018-08-21 21:54:10 +03:00
|
|
|
from .cext import osutil
|
2015-08-09 05:56:58 +03:00
|
|
|
from .i18n import _
|
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-03-26 21:54:44 +03:00
|
|
|
|
2009-07-05 13:01:30 +04:00
|
|
|
posixfile = open
|
2009-03-26 21:54:44 +03:00
|
|
|
normpath = os.path.normpath
|
|
|
|
samestat = os.path.samestat
|
2015-12-04 23:59:46 +03:00
|
|
|
try:
|
|
|
|
oslink = os.link
|
|
|
|
except AttributeError:
|
|
|
|
# Some platforms build Python without os.link on systems that are
|
|
|
|
# vaguely unix-like but don't have hardlink support. For those
|
|
|
|
# poor souls, just say we tried and that it failed so we fall back
|
|
|
|
# to copies.
|
|
|
|
def oslink(src, dst):
|
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 OSError(errno.EINVAL, "hardlinks not supported: %s to %s" % (src, dst))
|
|
|
|
|
|
|
|
|
2011-01-11 16:10:16 +03:00
|
|
|
unlink = os.unlink
|
2009-10-07 22:32:07 +04:00
|
|
|
rename = os.rename
|
2015-04-10 18:47:09 +03:00
|
|
|
removedirs = os.removedirs
|
2009-05-25 01:38:29 +04:00
|
|
|
expandglobs = False
|
2009-03-26 21:54:44 +03:00
|
|
|
|
2018-09-05 04:56:29 +03:00
|
|
|
O_CLOEXEC = osutil.O_CLOEXEC
|
|
|
|
|
2009-03-26 21:54:44 +03:00
|
|
|
umask = os.umask(0)
|
|
|
|
os.umask(umask)
|
|
|
|
|
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
|
|
|
|
2012-09-14 23:08:17 +04:00
|
|
|
def split(p):
|
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
|
|
|
"""Same as posixpath.split, but faster
|
2013-01-09 23:27:17 +04:00
|
|
|
|
|
|
|
>>> import posixpath
|
2017-09-03 08:32:11 +03:00
|
|
|
>>> for f in [b'/absolute/path/to/file',
|
|
|
|
... b'relative/path/to/file',
|
|
|
|
... b'file_alone',
|
|
|
|
... b'path/to/directory/',
|
|
|
|
... b'/multiple/path//separators',
|
|
|
|
... b'/file_at_root',
|
|
|
|
... b'///multiple_leading_separators_at_root',
|
|
|
|
... b'']:
|
2013-01-09 23:27:17 +04:00
|
|
|
... assert split(f) == posixpath.split(f), f
|
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
|
|
|
"""
|
|
|
|
ht = p.rsplit("/", 1)
|
2012-09-14 23:08:17 +04:00
|
|
|
if len(ht) == 1:
|
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 "", p
|
|
|
|
nh = ht[0].rstrip("/")
|
2012-09-14 23:08:17 +04:00
|
|
|
if nh:
|
|
|
|
return nh, ht[1]
|
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 ht[0] + "/", ht[1]
|
|
|
|
|
2012-09-14 23:08:17 +04:00
|
|
|
|
2018-08-09 02:07:25 +03:00
|
|
|
@contextlib.contextmanager
|
|
|
|
def _locked(pathname):
|
|
|
|
"""Context manager locking on a path. Use this to make short decisions
|
|
|
|
in an "atomic" way across multiple processes.
|
|
|
|
|
|
|
|
pathname must already exist.
|
|
|
|
"""
|
2018-09-05 04:56:29 +03:00
|
|
|
fd = os.open(pathname, os.O_RDONLY | os.O_NOFOLLOW | O_CLOEXEC)
|
2018-08-09 02:07:25 +03:00
|
|
|
fcntl.flock(fd, fcntl.LOCK_EX)
|
2018-04-18 03:16:45 +03:00
|
|
|
try:
|
2018-08-09 02:07:25 +03:00
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
os.close(fd)
|
|
|
|
|
|
|
|
|
2018-09-13 22:09:31 +03:00
|
|
|
def _issymlinklockstale(oldinfo, newinfo):
|
|
|
|
"""Test if the lock is stale (owned by dead process).
|
|
|
|
|
|
|
|
Only works for symlink locks. Both oldinfo and newinfo have the form:
|
|
|
|
|
|
|
|
info := namespace + ":" + pid
|
|
|
|
namespace := hostname (non-Linux) | hostname + "/" + pid-namespace (Linux)
|
|
|
|
|
|
|
|
Return True if it's certain that oldinfo is stale. Return False if it's not
|
|
|
|
or not sure.
|
|
|
|
"""
|
|
|
|
|
|
|
|
if ":" not in oldinfo or ":" not in newinfo:
|
|
|
|
# Malformed. Unsure.
|
|
|
|
return False
|
|
|
|
|
|
|
|
oldhost, oldpid = oldinfo.split(":", 1)
|
|
|
|
newhost, newpid = newinfo.split(":", 1)
|
|
|
|
|
|
|
|
if oldhost != newhost:
|
|
|
|
# Not in a same host, or namespace. Unsure.
|
|
|
|
return False
|
|
|
|
|
|
|
|
try:
|
|
|
|
pid = int(oldpid)
|
|
|
|
except ValueError:
|
|
|
|
# pid is not a number. Unsure.
|
|
|
|
return False
|
|
|
|
|
|
|
|
return not testpid(pid)
|
|
|
|
|
|
|
|
|
2018-08-09 02:07:25 +03:00
|
|
|
def makelock(info, pathname):
|
|
|
|
"""Try to make a lock at given path. Write info inside it.
|
|
|
|
|
2018-09-13 22:09:31 +03:00
|
|
|
Stale non-symlink or symlink locks are removed automatically. Symlink locks
|
|
|
|
are only used by legacy code, or by the new code temporarily to prevent
|
|
|
|
issues running together with the old code.
|
2018-08-09 02:07:25 +03:00
|
|
|
|
|
|
|
Return file descriptor on success. The file descriptor must be kept
|
|
|
|
for the lock to be effective.
|
|
|
|
|
2018-09-13 22:09:31 +03:00
|
|
|
Raise EAGAIN, likely caused by another process holding the lock.
|
|
|
|
Raise EEXIST or ELOOP, likely caused by another legacy hg process
|
|
|
|
holding the lock.
|
|
|
|
|
|
|
|
Can also raise other errors or those errors for other causes.
|
|
|
|
Callers should convert errors to error.LockHeld or error.LockUnavailable.
|
2018-08-09 02:07:25 +03:00
|
|
|
"""
|
|
|
|
|
|
|
|
# This is a bit complex, since it aims to support old lock code where the
|
|
|
|
# lock file is removed when the lock is released. The simpler version
|
|
|
|
# where the lock file does not get unlinked when releasing the lock is:
|
|
|
|
#
|
|
|
|
# # Open the file. Create on demand. Fail if it's a symlink.
|
2018-09-05 04:56:29 +03:00
|
|
|
# fd = os.open(pathname, os.O_CREAT | os.O_RDWR | os.O_NOFOLLOW | O_CLOEXEC)
|
2018-08-09 02:07:25 +03:00
|
|
|
# try:
|
|
|
|
# fcntl.flock(fd, fcntl.LOCK_NB | fcntl.LOCK_EX)
|
|
|
|
# os.write(fd, info)
|
|
|
|
# except (OSError, IOError):
|
|
|
|
# os.close(fd)
|
|
|
|
# raise
|
|
|
|
# else:
|
|
|
|
# return fd
|
|
|
|
#
|
|
|
|
# With "unlink" on release, the above simple logic can break in this way:
|
|
|
|
#
|
|
|
|
# [process 1] got fd.
|
|
|
|
# [process 2] got fd pointing to a same file.
|
|
|
|
# [process 1] .... release lock. file unlinked.
|
|
|
|
# [process 2] flock on fd. (broken lock - file was gone)
|
|
|
|
#
|
|
|
|
# A direct fix is to use O_EXCL to make sure the file is created by the
|
|
|
|
# current process, then use "flock". That means there needs to be a way to
|
|
|
|
# remove stale lock, and that is not easy. A naive check and delete can
|
|
|
|
# break subtly:
|
|
|
|
#
|
|
|
|
# [process 1] to check stale lock - got fd.
|
|
|
|
# [process 2] ... release lock. file unlinked.
|
|
|
|
# [process 1] flock taken, decided to remove file.
|
|
|
|
# [process 3] create a new lock.
|
|
|
|
# [process 1] unlink lock file. (wrong - removed the wrong lock)
|
|
|
|
#
|
|
|
|
# Instead of figuring out how to handle all corner cases carefully, we just
|
|
|
|
# always lock the parent directory when doing "racy" write operations
|
|
|
|
# (creating a lock, or removing a stale lock). So they become "atomic" and
|
|
|
|
# safe. There are 2 kinds of write operations that can happen without
|
|
|
|
# taking the directory lock:
|
|
|
|
#
|
|
|
|
# - Legacy symlink lock creation or deletion. The new code errors out
|
|
|
|
# when it saw a symlink lock (os.open(..., O_NOFOLLOW) and os.rename).
|
|
|
|
# So they play well with each other.
|
|
|
|
# - Unlinking lock file when when releasing. The release logic is holding
|
|
|
|
# the flock. So it knows nobody else has the lock. Therefore it can do
|
|
|
|
# the unlink without extra locking.
|
|
|
|
dirname = os.path.dirname(pathname)
|
|
|
|
with _locked(dirname or "."):
|
|
|
|
# Check and remove stale lock
|
|
|
|
try:
|
2018-09-05 04:56:29 +03:00
|
|
|
fd = os.open(pathname, os.O_RDONLY | os.O_NOFOLLOW | O_CLOEXEC)
|
2018-08-09 02:07:25 +03:00
|
|
|
except (OSError, IOError) as ex:
|
2018-09-13 22:09:31 +03:00
|
|
|
# ELOOP: symlink lock. Check if it's stale.
|
|
|
|
if ex.errno == errno.ELOOP:
|
|
|
|
oldinfo = os.readlink(pathname)
|
|
|
|
if _issymlinklockstale(oldinfo, info):
|
|
|
|
os.unlink(pathname)
|
|
|
|
elif ex.errno != errno.ENOENT:
|
2018-08-09 02:07:25 +03:00
|
|
|
raise
|
|
|
|
else:
|
|
|
|
try:
|
2018-09-13 22:09:31 +03:00
|
|
|
# Use fcntl to test stale lock
|
2018-08-09 02:07:25 +03:00
|
|
|
fcntl.flock(fd, fcntl.LOCK_NB | fcntl.LOCK_EX)
|
|
|
|
os.unlink(pathname)
|
|
|
|
except (OSError, IOError) as ex:
|
|
|
|
# EAGAIN: lock taken - return directly
|
|
|
|
# ENOENT: lock removed already - continue
|
|
|
|
if ex.errno != errno.ENOENT:
|
|
|
|
raise
|
|
|
|
finally:
|
|
|
|
os.close(fd)
|
|
|
|
|
|
|
|
# Create symlink placeholder. Make sure the file replaced by
|
|
|
|
# "os.rename" can only be this symlink. This avoids race condition
|
|
|
|
# when legacy code creates the symlink lock without locking the
|
|
|
|
# parent directory.
|
|
|
|
#
|
|
|
|
# This is basically the legacy lock logic.
|
|
|
|
placeholdercreated = False
|
|
|
|
try:
|
|
|
|
os.symlink(info, pathname)
|
|
|
|
placeholdercreated = True
|
|
|
|
except (IOError, OSError) as ex:
|
|
|
|
if ex.errno == errno.EEXIST:
|
|
|
|
raise
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if not placeholdercreated:
|
|
|
|
# No symlink support. Suboptimal. Create a placeholder by using an
|
|
|
|
# empty file. Other legacy process might see a "malformed lock"
|
|
|
|
# temporarily. New processes won't see this because both "readlock"
|
|
|
|
# and "islocked" take the directory lock.
|
2018-09-05 04:56:29 +03:00
|
|
|
fd = os.open(pathname, os.O_CREAT | os.O_WRONLY | os.O_EXCL | O_CLOEXEC)
|
2018-08-09 02:07:25 +03:00
|
|
|
os.close(fd)
|
|
|
|
|
|
|
|
try:
|
2018-09-13 22:09:29 +03:00
|
|
|
# Create new lock.
|
|
|
|
#
|
|
|
|
# mkstemp sets FD_CLOEXEC automatically. For thread-safety. Threads
|
|
|
|
# used here (progress, profiling, Winodws update worker) do not fork.
|
|
|
|
# So it's fine to not patch `os.open` here.
|
|
|
|
fd, tmppath = tempfile.mkstemp(prefix="makelock", dir=dirname)
|
|
|
|
try:
|
|
|
|
os.fchmod(fd, 0o664)
|
|
|
|
fcntl.flock(fd, fcntl.LOCK_NB | fcntl.LOCK_EX)
|
|
|
|
os.write(fd, info)
|
|
|
|
os.rename(tmppath, pathname)
|
|
|
|
return fd
|
|
|
|
except Exception:
|
|
|
|
unlink(tmppath)
|
|
|
|
os.close(fd)
|
|
|
|
raise
|
2018-08-09 02:07:25 +03:00
|
|
|
except Exception:
|
2018-09-13 22:09:29 +03:00
|
|
|
# Remove the placeholder
|
|
|
|
unlink(pathname)
|
2018-04-18 03:16:45 +03:00
|
|
|
raise
|
|
|
|
|
2018-08-09 02:07:25 +03:00
|
|
|
|
|
|
|
def readlock(pathname):
|
|
|
|
with _locked(os.path.dirname(pathname) or "."):
|
|
|
|
try:
|
|
|
|
return os.readlink(pathname)
|
|
|
|
except OSError as why:
|
|
|
|
if why.errno not in (errno.EINVAL, errno.ENOSYS):
|
|
|
|
raise
|
|
|
|
except AttributeError: # no symlink in os
|
|
|
|
pass
|
|
|
|
fp = posixfile(pathname)
|
|
|
|
r = fp.read()
|
|
|
|
fp.close()
|
|
|
|
return r
|
|
|
|
|
|
|
|
|
2018-09-05 04:56:29 +03:00
|
|
|
def releaselock(lockfd, pathname):
|
|
|
|
# Explicitly unlock. This avoids issues when a
|
|
|
|
# forked process inherits the flock.
|
|
|
|
fcntl.flock(lockfd, fcntl.LOCK_UN)
|
|
|
|
os.close(lockfd)
|
|
|
|
os.unlink(pathname)
|
|
|
|
|
|
|
|
|
2018-08-09 02:07:25 +03:00
|
|
|
def islocked(pathname):
|
|
|
|
with _locked(os.path.dirname(pathname) or "."):
|
|
|
|
try:
|
2018-09-05 04:56:29 +03:00
|
|
|
fd = os.open(pathname, os.O_RDONLY | os.O_NOFOLLOW | O_CLOEXEC)
|
2018-08-09 02:07:25 +03:00
|
|
|
except OSError as ex:
|
|
|
|
# ELOOP, ENOENT, EPERM, ...
|
|
|
|
# Only treat ENOENT as "not locked".
|
|
|
|
return ex.errno != errno.ENOENT
|
|
|
|
try:
|
|
|
|
fcntl.flock(fd, fcntl.LOCK_NB | fcntl.LOCK_EX)
|
|
|
|
return False
|
|
|
|
except IOError as ex:
|
|
|
|
if ex.errno == errno.EAGAIN:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
raise
|
|
|
|
finally:
|
|
|
|
os.close(fd)
|
2018-04-18 03:16:45 +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
|
|
|
|
2009-03-26 21:54:44 +03:00
|
|
|
def openhardlinks():
|
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 true if it is safe to hold open file handles to hardlinks"""
|
2009-03-26 21:54:44 +03:00
|
|
|
return True
|
|
|
|
|
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
|
|
|
|
2011-02-14 13:12:26 +03:00
|
|
|
def nlinks(name):
|
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 number of hardlinks for the given file"""
|
2011-02-14 13:12:26 +03:00
|
|
|
return os.lstat(name).st_nlink
|
|
|
|
|
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
|
|
|
|
2011-05-06 17:19:48 +04:00
|
|
|
def parsepatchoutput(output_line):
|
2009-06-09 17:25:17 +04:00
|
|
|
"""parses the output produced by patch and returns the filename"""
|
2009-03-26 21:54:44 +03:00
|
|
|
pf = output_line[14:]
|
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 pycompat.sysplatform == "OpenVMS":
|
|
|
|
if pf[0] == "`":
|
|
|
|
pf = pf[1:-1] # Remove the quotes
|
2009-03-26 21:54:44 +03:00
|
|
|
else:
|
2009-04-27 11:12:07 +04:00
|
|
|
if pf.startswith("'") and pf.endswith("'") and " " in pf:
|
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
|
|
|
pf = pf[1:-1] # Remove the quotes
|
2009-03-26 21:54:44 +03:00
|
|
|
return pf
|
|
|
|
|
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-03-26 21:54:44 +03:00
|
|
|
def sshargs(sshcmd, host, user, port):
|
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
|
|
|
"""Build argument list for ssh"""
|
2009-03-26 21:54:44 +03:00
|
|
|
args = user and ("%s@%s" % (user, host)) or host
|
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 args[:1]:
|
2017-08-04 21:00:03 +03:00
|
|
|
raise error.Abort(
|
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
|
|
|
_("illegal ssh hostname or username starting with -: %s") % args
|
|
|
|
)
|
2017-08-05 09:54:12 +03:00
|
|
|
args = shellquote(args)
|
|
|
|
if port:
|
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
|
|
|
args = "-p %s %s" % (shellquote(port), args)
|
2017-08-05 09:54:12 +03:00
|
|
|
return args
|
2009-03-26 21:54:44 +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
|
|
|
|
2011-05-08 22:45:47 +04:00
|
|
|
def isexec(f):
|
2009-03-26 21:54:44 +03:00
|
|
|
"""check whether a file is executable"""
|
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 os.lstat(f).st_mode & 0o100 != 0
|
|
|
|
|
2009-03-26 21:54:44 +03:00
|
|
|
|
2011-05-06 17:22:31 +04:00
|
|
|
def setflags(f, l, x):
|
2017-04-26 17:05:22 +03:00
|
|
|
st = os.lstat(f)
|
|
|
|
s = st.st_mode
|
2009-03-26 21:54:44 +03:00
|
|
|
if l:
|
|
|
|
if not stat.S_ISLNK(s):
|
|
|
|
# switch file to link
|
2010-12-24 17:23:01 +03:00
|
|
|
fp = open(f)
|
|
|
|
data = fp.read()
|
|
|
|
fp.close()
|
2017-03-21 16:50:28 +03:00
|
|
|
unlink(f)
|
2009-03-26 21:54:44 +03:00
|
|
|
try:
|
|
|
|
os.symlink(data, f)
|
2011-04-23 01:51:25 +04:00
|
|
|
except OSError:
|
2009-03-26 21:54:44 +03:00
|
|
|
# failed to make a link, rewrite file
|
2010-12-24 17:23:01 +03:00
|
|
|
fp = open(f, "w")
|
|
|
|
fp.write(data)
|
|
|
|
fp.close()
|
2009-03-26 21:54:44 +03:00
|
|
|
# no chmod needed at this point
|
|
|
|
return
|
|
|
|
if stat.S_ISLNK(s):
|
|
|
|
# switch link to file
|
|
|
|
data = os.readlink(f)
|
2017-03-21 16:50:28 +03:00
|
|
|
unlink(f)
|
2010-12-24 17:23:01 +03:00
|
|
|
fp = open(f, "w")
|
|
|
|
fp.write(data)
|
|
|
|
fp.close()
|
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
|
|
|
s = 0o666 & ~umask # avoid restatting for chmod
|
2009-03-26 21:54:44 +03:00
|
|
|
|
2015-06-24 08:30:33 +03:00
|
|
|
sx = s & 0o100
|
2017-04-26 17:05:22 +03:00
|
|
|
if st.st_nlink > 1 and bool(x) != bool(sx):
|
|
|
|
# the file is a hardlink, break it
|
|
|
|
with open(f, "rb") as fp:
|
|
|
|
data = fp.read()
|
|
|
|
unlink(f)
|
|
|
|
with open(f, "wb") as fp:
|
|
|
|
fp.write(data)
|
|
|
|
|
2009-03-26 21:54:44 +03:00
|
|
|
if x and not sx:
|
|
|
|
# Turn on +x for every +r bit when making a file executable
|
|
|
|
# and obey umask.
|
2015-06-24 08:30:33 +03:00
|
|
|
os.chmod(f, s | (s & 0o444) >> 2 & ~umask)
|
2009-03-26 21:54:44 +03:00
|
|
|
elif not x and sx:
|
|
|
|
# Turn off all +x bits
|
2015-06-24 08:30:33 +03:00
|
|
|
os.chmod(f, s & 0o666)
|
2009-03-26 21:54:44 +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
|
|
|
|
2011-08-02 15:18:56 +04:00
|
|
|
def copymode(src, dst, mode=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
|
|
|
"""Copy the file mode from the file at path src to dst.
|
2011-08-02 15:18:56 +04:00
|
|
|
If src doesn't exist, we're using mode instead. If mode is None, we're
|
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
|
|
|
using umask."""
|
2011-08-02 15:18:56 +04:00
|
|
|
try:
|
2015-06-24 08:30:33 +03:00
|
|
|
st_mode = os.lstat(src).st_mode & 0o777
|
2015-06-24 08:20:08 +03:00
|
|
|
except OSError as inst:
|
2011-08-02 15:18:56 +04:00
|
|
|
if inst.errno != errno.ENOENT:
|
|
|
|
raise
|
|
|
|
st_mode = mode
|
|
|
|
if st_mode is None:
|
|
|
|
st_mode = ~umask
|
2015-06-24 08:30:33 +03:00
|
|
|
st_mode &= 0o666
|
2011-08-02 15:18:56 +04:00
|
|
|
os.chmod(dst, st_mode)
|
|
|
|
|
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
|
|
|
|
2019-02-07 05:18:44 +03:00
|
|
|
def _findmountpoint(dirpath):
|
|
|
|
"""Return the mount point of dirpath (best-effort)"""
|
|
|
|
path = os.path.abspath(dirpath)
|
|
|
|
while True:
|
|
|
|
if os.path.ismount(path):
|
|
|
|
return path
|
|
|
|
nextpath = os.path.dirname(path)
|
|
|
|
if nextpath == path:
|
|
|
|
return None
|
|
|
|
path = nextpath
|
|
|
|
|
|
|
|
|
|
|
|
def _findstdev(mountpoint):
|
|
|
|
"""Return st_dev major:minor (ex. "8:1") for the given mountpoint.
|
|
|
|
|
|
|
|
Linux-only. Require /proc to be mounted properly.
|
|
|
|
"""
|
|
|
|
if mountpoint:
|
|
|
|
try:
|
|
|
|
for line in open("/proc/self/mountinfo"):
|
|
|
|
# Refer to "man 5 proc" for the format of mountinfo
|
|
|
|
columns = line.split(" ")
|
|
|
|
if len(columns) != 11:
|
|
|
|
continue
|
|
|
|
if mountpoint == columns[4]:
|
|
|
|
stdev = columns[2]
|
|
|
|
return stdev
|
|
|
|
except (OSError, IOError):
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def _findudevprops(stdev):
|
|
|
|
"""Return udev properties as a dict (best-effort) for a block device.
|
|
|
|
|
|
|
|
Linux-only. stdev is a string returned by _findstdev.
|
|
|
|
"""
|
|
|
|
# "b": block device
|
|
|
|
udevpath = "/run/udev/data/b%s" % stdev
|
|
|
|
try:
|
|
|
|
return dict(l.rstrip().split("=", 1) for l in open(udevpath) if "=" in l)
|
|
|
|
except (OSError, IOError):
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
2018-08-21 21:54:10 +03:00
|
|
|
def getfstype(dirpath):
|
|
|
|
"""Get the filesystem type name from a directory (best-effort)
|
|
|
|
|
2018-08-21 22:19:45 +03:00
|
|
|
Returns None if we are unsure, or hit errors like ENOENT, EPERM, etc.
|
2018-08-21 21:54:10 +03:00
|
|
|
"""
|
2018-08-21 22:19:45 +03:00
|
|
|
try:
|
|
|
|
if _iseden(dirpath):
|
|
|
|
return "eden"
|
2019-02-07 05:18:44 +03:00
|
|
|
result = osutil.getfstype(dirpath)
|
|
|
|
if result == "fuse" and pycompat.islinux:
|
|
|
|
# Spend some extra efforts to find out the actual filesystem
|
|
|
|
stdev = _findstdev(_findmountpoint(dirpath))
|
|
|
|
if stdev:
|
|
|
|
props = _findudevprops(stdev)
|
|
|
|
# The name is used in well-known projects: systemd (udev) and
|
|
|
|
# util-linux (libblkid). Although it does not seem to be
|
|
|
|
# documented publicly.
|
|
|
|
fstype = props.get("E:ID_FS_TYPE")
|
|
|
|
if fstype:
|
|
|
|
result += ".%s" % fstype
|
2018-08-21 22:19:45 +03:00
|
|
|
except (IOError, OSError):
|
|
|
|
# Not fatal
|
2019-02-07 05:18:44 +03:00
|
|
|
result = None
|
|
|
|
return result
|
2018-08-21 21:54:10 +03:00
|
|
|
|
|
|
|
|
checklink and checkexec avoid mutating eden filesystem root inode
Summary:
While examining a system where Eden was under load we discovered
that an application had gotten into a feedback loop; it was asking watchman
to tell it about changes in the repo, and each time a change occurred it
would run `hg status` and `hg log`. These commands triggered the checkexec
and checklink code to modify the filesystem, which in turn generated change
events for the application to consume.
The application already filters out changes under the `.hg` directory, but
these probe files are not placed there. Inspecting the code shows that it
has the ability to use `.hg/cache` for this purpose, but as far as I can
tell, nothing ever creates this directory in the working copies in common
use.
I made an initial pass at creating that directory in these functions in
D9322798, but there are hg tests that are sensitive to the precise mode of that
dir. The semantics and creation of that dir are not clear, so I'm just going
for a simpler option: moving the files under the `.hg` dir if that dir exists.
Moving these files is desirable because it simplifies ignore logic for
downstream clients, and takes pressure off the root inode in an eden mount,
which is more expensive to save changes into than the others due to its
stronger durability requirements.
However, the `.hg` directory may not even be on the same filesystem as the
rest of the working copy.
For the sake of an expedient fix, this diff checks to see if we're inside an
eden mount and uses that information to inform the caller; eden mounts
on posix systems support both symlinks and exec bits.
Reviewed By: quark-zju
Differential Revision: D9328199
fbshipit-source-id: 38af8e3d95e7acee103a1fcc52277511fd45e9fc
2018-08-18 03:53:00 +03:00
|
|
|
def _iseden(dirpath):
|
|
|
|
"""Returns True if the specified directory is the root directory of,
|
|
|
|
or is a sub-directory of an Eden mount."""
|
|
|
|
return os.path.islink(os.path.join(dirpath, ".eden", "root"))
|
|
|
|
|
|
|
|
|
2018-02-10 04:31:41 +03:00
|
|
|
def _checkexec(path):
|
2011-04-04 13:41:54 +04:00
|
|
|
"""
|
|
|
|
Check whether the given path is on a filesystem with UNIX-like exec flags
|
|
|
|
|
|
|
|
Requires a directory (like /foo/.hg)
|
|
|
|
"""
|
|
|
|
|
2018-08-21 22:19:45 +03:00
|
|
|
cap = fscap.getfscap(getfstype(path), fscap.EXECBIT)
|
|
|
|
if cap is not None:
|
|
|
|
return cap
|
checklink and checkexec avoid mutating eden filesystem root inode
Summary:
While examining a system where Eden was under load we discovered
that an application had gotten into a feedback loop; it was asking watchman
to tell it about changes in the repo, and each time a change occurred it
would run `hg status` and `hg log`. These commands triggered the checkexec
and checklink code to modify the filesystem, which in turn generated change
events for the application to consume.
The application already filters out changes under the `.hg` directory, but
these probe files are not placed there. Inspecting the code shows that it
has the ability to use `.hg/cache` for this purpose, but as far as I can
tell, nothing ever creates this directory in the working copies in common
use.
I made an initial pass at creating that directory in these functions in
D9322798, but there are hg tests that are sensitive to the precise mode of that
dir. The semantics and creation of that dir are not clear, so I'm just going
for a simpler option: moving the files under the `.hg` dir if that dir exists.
Moving these files is desirable because it simplifies ignore logic for
downstream clients, and takes pressure off the root inode in an eden mount,
which is more expensive to save changes into than the others due to its
stronger durability requirements.
However, the `.hg` directory may not even be on the same filesystem as the
rest of the working copy.
For the sake of an expedient fix, this diff checks to see if we're inside an
eden mount and uses that information to inform the caller; eden mounts
on posix systems support both symlinks and exec bits.
Reviewed By: quark-zju
Differential Revision: D9328199
fbshipit-source-id: 38af8e3d95e7acee103a1fcc52277511fd45e9fc
2018-08-18 03:53:00 +03:00
|
|
|
|
2011-04-04 13:41:54 +04:00
|
|
|
# VFAT on some Linux versions can flip mode but it doesn't persist
|
|
|
|
# a FS remount. Frequently we can detect it if files are created
|
|
|
|
# with exec bit on.
|
|
|
|
|
|
|
|
try:
|
|
|
|
EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
|
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
|
|
|
cachedir = os.path.join(path, ".hg", "cache")
|
posix: give checkexec a fast path; keep the check files and test read only
Before, Mercurial would create a new temporary file every time, stat it, change
its exec mode, stat it again, and delete it. Most of this dance was done to
handle the rare and not-so-essential case of VFAT mounts on unix. The cost of
that was paid by the much more common and important case of using normal file
systems.
Instead, try to create and preserve .hg/cache/checkisexec and
.hg/cache/checknoexec with and without exec flag set. If the files exist and
have correct exec flags set, we can conclude that that file system supports the
exec flag. Best case, the whole exec check can thus be done with two stat
calls. Worst case, we delete the wrong files and check as usual. That will be
because temporary loss of exec bit or on file systems without support for the
exec bit. In that case we check as we did before, with the additional overhead
of one extra stat call.
It is possible that this different test algorithm in some cases on odd file
systems will give different behaviour. Again, I think it will be rare and
special cases and I think it is worth the risk.
test-clone.t happens to show the situation where checkisexec is left behind
from the old style check, while checknoexec only will be created next time a
exec check will be performed.
2015-01-14 03:15:26 +03:00
|
|
|
if os.path.isdir(cachedir):
|
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
|
|
|
checkisexec = os.path.join(cachedir, "checkisexec")
|
|
|
|
checknoexec = os.path.join(cachedir, "checknoexec")
|
posix: give checkexec a fast path; keep the check files and test read only
Before, Mercurial would create a new temporary file every time, stat it, change
its exec mode, stat it again, and delete it. Most of this dance was done to
handle the rare and not-so-essential case of VFAT mounts on unix. The cost of
that was paid by the much more common and important case of using normal file
systems.
Instead, try to create and preserve .hg/cache/checkisexec and
.hg/cache/checknoexec with and without exec flag set. If the files exist and
have correct exec flags set, we can conclude that that file system supports the
exec flag. Best case, the whole exec check can thus be done with two stat
calls. Worst case, we delete the wrong files and check as usual. That will be
because temporary loss of exec bit or on file systems without support for the
exec bit. In that case we check as we did before, with the additional overhead
of one extra stat call.
It is possible that this different test algorithm in some cases on odd file
systems will give different behaviour. Again, I think it will be rare and
special cases and I think it is worth the risk.
test-clone.t happens to show the situation where checkisexec is left behind
from the old style check, while checknoexec only will be created next time a
exec check will be performed.
2015-01-14 03:15:26 +03:00
|
|
|
|
|
|
|
try:
|
|
|
|
m = os.stat(checkisexec).st_mode
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno != errno.ENOENT:
|
|
|
|
raise
|
|
|
|
# checkisexec does not exist - fall through ...
|
|
|
|
else:
|
|
|
|
# checkisexec exists, check if it actually is exec
|
|
|
|
if m & EXECFLAGS != 0:
|
|
|
|
# ensure checkisexec exists, check it isn't exec
|
|
|
|
try:
|
|
|
|
m = os.stat(checknoexec).st_mode
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno != errno.ENOENT:
|
|
|
|
raise
|
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
|
|
|
open(checknoexec, "w").close() # might fail
|
posix: give checkexec a fast path; keep the check files and test read only
Before, Mercurial would create a new temporary file every time, stat it, change
its exec mode, stat it again, and delete it. Most of this dance was done to
handle the rare and not-so-essential case of VFAT mounts on unix. The cost of
that was paid by the much more common and important case of using normal file
systems.
Instead, try to create and preserve .hg/cache/checkisexec and
.hg/cache/checknoexec with and without exec flag set. If the files exist and
have correct exec flags set, we can conclude that that file system supports the
exec flag. Best case, the whole exec check can thus be done with two stat
calls. Worst case, we delete the wrong files and check as usual. That will be
because temporary loss of exec bit or on file systems without support for the
exec bit. In that case we check as we did before, with the additional overhead
of one extra stat call.
It is possible that this different test algorithm in some cases on odd file
systems will give different behaviour. Again, I think it will be rare and
special cases and I think it is worth the risk.
test-clone.t happens to show the situation where checkisexec is left behind
from the old style check, while checknoexec only will be created next time a
exec check will be performed.
2015-01-14 03:15:26 +03:00
|
|
|
m = os.stat(checknoexec).st_mode
|
|
|
|
if m & EXECFLAGS == 0:
|
|
|
|
# check-exec is exec and check-no-exec is not exec
|
|
|
|
return True
|
|
|
|
# checknoexec exists but is exec - delete it
|
2017-03-21 16:50:28 +03:00
|
|
|
unlink(checknoexec)
|
posix: give checkexec a fast path; keep the check files and test read only
Before, Mercurial would create a new temporary file every time, stat it, change
its exec mode, stat it again, and delete it. Most of this dance was done to
handle the rare and not-so-essential case of VFAT mounts on unix. The cost of
that was paid by the much more common and important case of using normal file
systems.
Instead, try to create and preserve .hg/cache/checkisexec and
.hg/cache/checknoexec with and without exec flag set. If the files exist and
have correct exec flags set, we can conclude that that file system supports the
exec flag. Best case, the whole exec check can thus be done with two stat
calls. Worst case, we delete the wrong files and check as usual. That will be
because temporary loss of exec bit or on file systems without support for the
exec bit. In that case we check as we did before, with the additional overhead
of one extra stat call.
It is possible that this different test algorithm in some cases on odd file
systems will give different behaviour. Again, I think it will be rare and
special cases and I think it is worth the risk.
test-clone.t happens to show the situation where checkisexec is left behind
from the old style check, while checknoexec only will be created next time a
exec check will be performed.
2015-01-14 03:15:26 +03:00
|
|
|
# checkisexec exists but is not exec - delete it
|
2017-03-21 16:50:28 +03:00
|
|
|
unlink(checkisexec)
|
posix: give checkexec a fast path; keep the check files and test read only
Before, Mercurial would create a new temporary file every time, stat it, change
its exec mode, stat it again, and delete it. Most of this dance was done to
handle the rare and not-so-essential case of VFAT mounts on unix. The cost of
that was paid by the much more common and important case of using normal file
systems.
Instead, try to create and preserve .hg/cache/checkisexec and
.hg/cache/checknoexec with and without exec flag set. If the files exist and
have correct exec flags set, we can conclude that that file system supports the
exec flag. Best case, the whole exec check can thus be done with two stat
calls. Worst case, we delete the wrong files and check as usual. That will be
because temporary loss of exec bit or on file systems without support for the
exec bit. In that case we check as we did before, with the additional overhead
of one extra stat call.
It is possible that this different test algorithm in some cases on odd file
systems will give different behaviour. Again, I think it will be rare and
special cases and I think it is worth the risk.
test-clone.t happens to show the situation where checkisexec is left behind
from the old style check, while checknoexec only will be created next time a
exec check will be performed.
2015-01-14 03:15:26 +03:00
|
|
|
|
|
|
|
# check using one file, leave it as checkisexec
|
|
|
|
checkdir = cachedir
|
|
|
|
else:
|
|
|
|
# check directly in path and don't leave checkisexec behind
|
|
|
|
checkdir = path
|
|
|
|
checkisexec = 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
|
|
|
fh, fn = tempfile.mkstemp(dir=checkdir, prefix="hg-checkexec-")
|
2011-04-04 13:41:54 +04:00
|
|
|
try:
|
|
|
|
os.close(fh)
|
2015-01-14 03:15:26 +03:00
|
|
|
m = os.stat(fn).st_mode
|
posix: give checkexec a fast path; keep the check files and test read only
Before, Mercurial would create a new temporary file every time, stat it, change
its exec mode, stat it again, and delete it. Most of this dance was done to
handle the rare and not-so-essential case of VFAT mounts on unix. The cost of
that was paid by the much more common and important case of using normal file
systems.
Instead, try to create and preserve .hg/cache/checkisexec and
.hg/cache/checknoexec with and without exec flag set. If the files exist and
have correct exec flags set, we can conclude that that file system supports the
exec flag. Best case, the whole exec check can thus be done with two stat
calls. Worst case, we delete the wrong files and check as usual. That will be
because temporary loss of exec bit or on file systems without support for the
exec bit. In that case we check as we did before, with the additional overhead
of one extra stat call.
It is possible that this different test algorithm in some cases on odd file
systems will give different behaviour. Again, I think it will be rare and
special cases and I think it is worth the risk.
test-clone.t happens to show the situation where checkisexec is left behind
from the old style check, while checknoexec only will be created next time a
exec check will be performed.
2015-01-14 03:15:26 +03:00
|
|
|
if m & EXECFLAGS == 0:
|
|
|
|
os.chmod(fn, m & 0o777 | EXECFLAGS)
|
|
|
|
if os.stat(fn).st_mode & EXECFLAGS != 0:
|
|
|
|
if checkisexec is not None:
|
|
|
|
os.rename(fn, checkisexec)
|
|
|
|
fn = None
|
|
|
|
return True
|
2011-04-04 13:41:54 +04:00
|
|
|
finally:
|
posix: give checkexec a fast path; keep the check files and test read only
Before, Mercurial would create a new temporary file every time, stat it, change
its exec mode, stat it again, and delete it. Most of this dance was done to
handle the rare and not-so-essential case of VFAT mounts on unix. The cost of
that was paid by the much more common and important case of using normal file
systems.
Instead, try to create and preserve .hg/cache/checkisexec and
.hg/cache/checknoexec with and without exec flag set. If the files exist and
have correct exec flags set, we can conclude that that file system supports the
exec flag. Best case, the whole exec check can thus be done with two stat
calls. Worst case, we delete the wrong files and check as usual. That will be
because temporary loss of exec bit or on file systems without support for the
exec bit. In that case we check as we did before, with the additional overhead
of one extra stat call.
It is possible that this different test algorithm in some cases on odd file
systems will give different behaviour. Again, I think it will be rare and
special cases and I think it is worth the risk.
test-clone.t happens to show the situation where checkisexec is left behind
from the old style check, while checknoexec only will be created next time a
exec check will be performed.
2015-01-14 03:15:26 +03:00
|
|
|
if fn is not None:
|
2017-03-21 16:50:28 +03:00
|
|
|
unlink(fn)
|
2011-04-04 13:41:54 +04:00
|
|
|
except (IOError, OSError):
|
|
|
|
# we don't care, the user probably won't be able to commit anyway
|
|
|
|
return 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
|
|
|
|
2018-02-10 04:31:41 +03:00
|
|
|
def _checklink(path):
|
2011-04-05 13:55:52 +04:00
|
|
|
"""check whether the given path is on a symlink-capable filesystem"""
|
2018-08-21 22:19:45 +03:00
|
|
|
cap = fscap.getfscap(getfstype(path), fscap.SYMLINK)
|
|
|
|
if cap is not None:
|
|
|
|
return cap
|
|
|
|
|
2011-04-05 13:55:52 +04:00
|
|
|
# mktemp is not racy because symlink creation will fail if the
|
|
|
|
# file already exists
|
2015-11-07 00:23:10 +03:00
|
|
|
while True:
|
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
|
|
|
cachedir = os.path.join(path, ".hg", "cache")
|
|
|
|
checklink = os.path.join(cachedir, "checklink")
|
2015-01-14 03:15:26 +03:00
|
|
|
# try fast path, read only
|
|
|
|
if os.path.islink(checklink):
|
|
|
|
return True
|
2016-11-17 14:59:36 +03:00
|
|
|
if os.path.isdir(cachedir):
|
|
|
|
checkdir = cachedir
|
|
|
|
else:
|
|
|
|
checkdir = path
|
|
|
|
cachedir = None
|
2017-03-19 08:06:47 +03:00
|
|
|
fscheckdir = pycompat.fsdecode(checkdir)
|
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
|
|
|
name = tempfile.mktemp(dir=fscheckdir, prefix=r"checklink-")
|
2017-03-19 08:06:47 +03:00
|
|
|
name = pycompat.fsencode(name)
|
2014-10-15 23:13:43 +04:00
|
|
|
try:
|
2016-11-30 19:39:36 +03:00
|
|
|
fd = None
|
|
|
|
if cachedir is 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
|
|
|
fd = tempfile.NamedTemporaryFile(
|
|
|
|
dir=fscheckdir, prefix=r"hg-checklink-"
|
|
|
|
)
|
2017-03-19 08:06:47 +03:00
|
|
|
target = pycompat.fsencode(os.path.basename(fd.name))
|
2016-11-30 19:39:36 +03:00
|
|
|
else:
|
|
|
|
# create a fixed file to link to; doesn't matter if it
|
|
|
|
# already exists.
|
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
|
|
|
target = "checklink-target"
|
2017-05-22 01:36:28 +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
|
|
|
open(os.path.join(cachedir, target), "w").close()
|
2017-05-22 01:36:28 +03:00
|
|
|
except IOError as inst:
|
|
|
|
if inst[0] == errno.EACCES:
|
|
|
|
# If we can't write to cachedir, just pretend
|
|
|
|
# that the fs is readonly and by association
|
|
|
|
# that the fs won't support symlinks. This
|
|
|
|
# seems like the least dangerous way to avoid
|
|
|
|
# data loss.
|
|
|
|
return False
|
|
|
|
raise
|
2015-11-07 00:23:10 +03:00
|
|
|
try:
|
2016-11-30 19:39:36 +03:00
|
|
|
os.symlink(target, name)
|
2015-01-14 03:15:26 +03:00
|
|
|
if cachedir is None:
|
2017-03-21 16:50:28 +03:00
|
|
|
unlink(name)
|
2015-01-14 03:15:26 +03:00
|
|
|
else:
|
|
|
|
try:
|
|
|
|
os.rename(name, checklink)
|
|
|
|
except OSError:
|
2017-03-21 16:50:28 +03:00
|
|
|
unlink(name)
|
2015-11-07 00:23:10 +03:00
|
|
|
return True
|
|
|
|
except OSError as inst:
|
|
|
|
# link creation might race, try again
|
|
|
|
if inst[0] == errno.EEXIST:
|
|
|
|
continue
|
2015-11-10 00:53:11 +03:00
|
|
|
raise
|
2015-11-07 00:23:10 +03:00
|
|
|
finally:
|
2016-11-30 19:39:36 +03:00
|
|
|
if fd is not None:
|
|
|
|
fd.close()
|
2015-11-07 00:23:10 +03:00
|
|
|
except AttributeError:
|
|
|
|
return False
|
2015-11-10 00:53:11 +03:00
|
|
|
except OSError as inst:
|
|
|
|
# sshfs might report failure while successfully creating the link
|
|
|
|
if inst[0] == errno.EIO and os.path.exists(name):
|
2017-03-21 16:50:28 +03:00
|
|
|
unlink(name)
|
2015-11-10 00:53:11 +03:00
|
|
|
return False
|
2011-04-05 13:55:52 +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
|
|
|
|
2018-05-23 09:25:25 +03:00
|
|
|
def _checkbrokensymlink(path, msg=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
|
|
|
"""Check if path or one of its parent directory is a broken symlink. Raise
|
2018-05-23 09:25:25 +03:00
|
|
|
more detailed error about it.
|
|
|
|
|
|
|
|
Subject to filesystem races. ONLY call this when there is already an ENONET
|
|
|
|
error.
|
|
|
|
|
|
|
|
If msg is set, it would be used as extra context in the error message.
|
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-05-23 09:25:25 +03:00
|
|
|
src = path
|
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
|
|
|
while src not in ("", "/"):
|
2018-05-23 09:25:25 +03:00
|
|
|
src = os.path.dirname(src)
|
|
|
|
errmsg = None
|
|
|
|
try:
|
|
|
|
if os.path.islink(src):
|
|
|
|
dest = os.readlink(src)
|
|
|
|
if not os.path.exists(src):
|
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
|
|
|
errmsg = "Symlink %r points to non-existed destination %r" % (
|
|
|
|
src,
|
|
|
|
dest,
|
|
|
|
)
|
2018-05-23 09:25:25 +03:00
|
|
|
if msg:
|
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
|
|
|
errmsg += " during %s" % msg
|
2018-05-23 09:25:25 +03:00
|
|
|
except OSError:
|
|
|
|
# Ignore filesystem races (ex. "src" is deleted before readlink)
|
|
|
|
pass
|
|
|
|
if errmsg:
|
|
|
|
raise OSError(errno.ENOENT, errmsg, path)
|
|
|
|
|
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
|
|
|
|
2011-04-06 20:09:43 +04:00
|
|
|
def checkosfilename(path):
|
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
|
|
|
"""Check that the base-relative path is a valid filename on this platform.
|
|
|
|
Returns None if the path is ok, or a UI string describing the problem."""
|
|
|
|
return None # on posix platforms, every path is ok
|
|
|
|
|
2011-04-06 20:09:43 +04:00
|
|
|
|
2011-05-06 17:25:35 +04:00
|
|
|
def setbinary(fd):
|
2009-03-26 21:54:44 +03:00
|
|
|
pass
|
|
|
|
|
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-03-26 21:54:44 +03:00
|
|
|
def pconvert(path):
|
|
|
|
return path
|
|
|
|
|
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-03-26 21:54:44 +03:00
|
|
|
def localpath(path):
|
|
|
|
return path
|
|
|
|
|
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
|
|
|
|
2010-01-08 16:18:39 +03:00
|
|
|
def samefile(fpath1, fpath2):
|
|
|
|
"""Returns whether path1 and path2 refer to the same file. This is only
|
|
|
|
guaranteed to work for files, not directories."""
|
|
|
|
return os.path.samefile(fpath1, fpath2)
|
|
|
|
|
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
|
|
|
|
2010-01-08 16:18:39 +03:00
|
|
|
def samedevice(fpath1, fpath2):
|
|
|
|
"""Returns whether fpath1 and fpath2 are on the same device. This is only
|
|
|
|
guaranteed to work for files, not directories."""
|
|
|
|
st1 = os.lstat(fpath1)
|
|
|
|
st2 = os.lstat(fpath2)
|
|
|
|
return st1.st_dev == st2.st_dev
|
|
|
|
|
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-06-07 21:24:38 +03:00
|
|
|
def getmaxrss():
|
|
|
|
"""Returns the maximum resident set size of this process, in bytes"""
|
|
|
|
res = resource.getrusage(resource.RUSAGE_SELF)
|
|
|
|
|
|
|
|
# Linux returns the maxrss in KB, whereas macOS returns in bytes.
|
|
|
|
if pycompat.isdarwin:
|
|
|
|
return res.ru_maxrss
|
|
|
|
else:
|
|
|
|
return res.ru_maxrss * 1024
|
|
|
|
|
|
|
|
|
2017-10-13 09:34:34 +03:00
|
|
|
if pycompat.isdarwin:
|
2011-11-23 03:26:32 +04:00
|
|
|
|
|
|
|
def normcase(path):
|
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-05-04 23:51:21 +04:00
|
|
|
Normalize a filename for OS X-compatible comparison:
|
|
|
|
- escape-encode invalid characters
|
|
|
|
- decompose to NFD
|
|
|
|
- lowercase
|
2014-12-16 21:07:10 +03:00
|
|
|
- omit ignored characters [200c-200f, 202a-202e, 206a-206f,feff]
|
2013-05-04 23:51:21 +04:00
|
|
|
|
2017-09-03 08:32:11 +03:00
|
|
|
>>> normcase(b'UPPER')
|
2013-05-04 23:51:21 +04:00
|
|
|
'upper'
|
2017-09-16 02:43:02 +03:00
|
|
|
>>> normcase(b'Caf\\xc3\\xa9')
|
2013-05-04 23:51:21 +04:00
|
|
|
'cafe\\xcc\\x81'
|
2017-09-16 02:43:02 +03:00
|
|
|
>>> normcase(b'\\xc3\\x89')
|
2013-05-04 23:51:21 +04:00
|
|
|
'e\\xcc\\x81'
|
2017-09-16 02:43:02 +03:00
|
|
|
>>> normcase(b'\\xb8\\xca\\xc3\\xca\\xbe\\xc8.JPG') # issue3918
|
2013-05-04 23:51:21 +04:00
|
|
|
'%b8%ca%c3\\xca\\xbe%c8.jpg'
|
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-05-04 23:51:21 +04:00
|
|
|
|
2013-01-29 20:01:41 +04:00
|
|
|
try:
|
2014-10-04 05:47:28 +04:00
|
|
|
return encoding.asciilower(path) # exception for non-ASCII
|
2013-01-29 20:01:41 +04:00
|
|
|
except UnicodeDecodeError:
|
2015-04-01 09:30:19 +03:00
|
|
|
return normcasefallback(path)
|
|
|
|
|
|
|
|
normcasespec = encoding.normcasespecs.lower
|
|
|
|
|
|
|
|
def normcasefallback(path):
|
2011-11-23 03:26:32 +04: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
|
|
|
u = path.decode("utf-8")
|
2011-11-23 03:26:32 +04:00
|
|
|
except UnicodeDecodeError:
|
2013-05-04 23:51:21 +04:00
|
|
|
# OS X percent-encodes any bytes that aren't valid utf-8
|
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
|
|
|
s = ""
|
2015-11-06 02:09:00 +03:00
|
|
|
pos = 0
|
2015-12-13 06:36:21 +03:00
|
|
|
l = len(path)
|
2015-11-06 02:09:00 +03:00
|
|
|
while pos < l:
|
|
|
|
try:
|
|
|
|
c = encoding.getutf8char(path, pos)
|
|
|
|
pos += len(c)
|
|
|
|
except ValueError:
|
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
|
|
|
c = "%%%02X" % ord(path[pos : pos + 1])
|
2015-11-06 02:09:00 +03:00
|
|
|
pos += 1
|
|
|
|
s += c
|
|
|
|
|
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
|
|
|
u = s.decode("utf-8")
|
2011-11-23 03:26:32 +04:00
|
|
|
|
|
|
|
# Decompose then lowercase (HFS+ technote specifies lower)
|
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
|
|
|
enc = unicodedata.normalize(r"NFD", u).lower().encode("utf-8")
|
2014-12-16 21:07:10 +03:00
|
|
|
# drop HFS+ ignored characters
|
|
|
|
return encoding.hfsignoreclean(enc)
|
2011-11-23 03:26:32 +04:00
|
|
|
|
2018-02-10 04:31:41 +03:00
|
|
|
checkexec = _checkexec
|
|
|
|
checklink = _checklink
|
|
|
|
|
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
|
|
|
elif pycompat.sysplatform == "cygwin":
|
2011-12-16 16:21:08 +04:00
|
|
|
# workaround for cygwin, in which mount point part of path is
|
|
|
|
# treated as case sensitive, even though underlying NTFS is case
|
|
|
|
# insensitive.
|
|
|
|
|
|
|
|
# default mount points
|
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
|
|
|
cygwinmountpoints = sorted(["/usr/bin", "/usr/lib", "/cygdrive"], reverse=True)
|
2011-12-16 16:21:08 +04:00
|
|
|
|
|
|
|
# use upper-ing as normcase as same as NTFS workaround
|
|
|
|
def normcase(path):
|
|
|
|
pathlen = len(path)
|
2016-12-17 17:32:50 +03:00
|
|
|
if (pathlen == 0) or (path[0] != pycompat.ossep):
|
2011-12-16 16:21:08 +04:00
|
|
|
# treat as relative
|
2012-07-18 16:41:58 +04:00
|
|
|
return encoding.upper(path)
|
2011-12-16 16:21:08 +04:00
|
|
|
|
|
|
|
# to preserve case of mountpoint part
|
|
|
|
for mp in cygwinmountpoints:
|
|
|
|
if not path.startswith(mp):
|
|
|
|
continue
|
|
|
|
|
|
|
|
mplen = len(mp)
|
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 mplen == pathlen: # mount point itself
|
2011-12-16 16:21:08 +04:00
|
|
|
return mp
|
2016-12-17 17:32:50 +03:00
|
|
|
if path[mplen] == pycompat.ossep:
|
2012-07-18 16:41:58 +04:00
|
|
|
return mp + encoding.upper(path[mplen:])
|
2011-12-16 16:21:08 +04:00
|
|
|
|
2012-07-18 16:41:58 +04:00
|
|
|
return encoding.upper(path)
|
2011-12-16 16:21:08 +04:00
|
|
|
|
2015-04-01 10:29:22 +03:00
|
|
|
normcasespec = encoding.normcasespecs.other
|
|
|
|
normcasefallback = normcase
|
|
|
|
|
2012-03-09 00:17:36 +04:00
|
|
|
# Cygwin translates native ACLs to POSIX permissions,
|
|
|
|
# but these translations are not supported by native
|
|
|
|
# tools, so the exec bit tends to be set erroneously.
|
|
|
|
# Therefore, disable executable bit access on Cygwin.
|
|
|
|
def checkexec(path):
|
|
|
|
return False
|
|
|
|
|
2012-03-09 01:59:47 +04:00
|
|
|
# Similarly, Cygwin's symlink emulation is likely to create
|
|
|
|
# problems when Mercurial is used from both Cygwin and native
|
|
|
|
# Windows, with other native tools, or on shared volumes
|
|
|
|
def checklink(path):
|
|
|
|
return 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
|
|
|
|
2018-02-10 04:31:41 +03:00
|
|
|
else:
|
|
|
|
# os.path.normcase is a no-op, which doesn't help us on non-native
|
|
|
|
# filesystems
|
|
|
|
def normcase(path):
|
|
|
|
return path.lower()
|
|
|
|
|
|
|
|
# what normcase does to ASCII strings
|
|
|
|
normcasespec = encoding.normcasespecs.lower
|
|
|
|
# fallback normcase function for non-ASCII strings
|
|
|
|
normcasefallback = normcase
|
|
|
|
|
|
|
|
checkexec = _checkexec
|
|
|
|
checklink = _checklink
|
|
|
|
|
2014-12-25 17:33:26 +03:00
|
|
|
_needsshellquote = 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
|
|
|
|
|
|
|
|
2009-03-26 21:54:44 +03:00
|
|
|
def shellquote(s):
|
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 pycompat.sysplatform == "OpenVMS":
|
2009-03-26 21:54:44 +03:00
|
|
|
return '"%s"' % s
|
2014-12-25 17:33:26 +03:00
|
|
|
global _needsshellquote
|
|
|
|
if _needsshellquote is 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
|
|
|
_needsshellquote = re.compile(br"[^a-zA-Z0-9._/+-]").search
|
2015-02-11 13:57:07 +03:00
|
|
|
if s and not _needsshellquote(s):
|
2014-12-25 17:33:26 +03:00
|
|
|
# "s" shouldn't have to be quoted
|
|
|
|
return s
|
2009-03-26 21:54:44 +03:00
|
|
|
else:
|
|
|
|
return "'%s'" % s.replace("'", "'\\''")
|
|
|
|
|
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-03-26 21:54:44 +03:00
|
|
|
def quotecommand(cmd):
|
|
|
|
return cmd
|
|
|
|
|
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 popen(command, mode="r"):
|
2009-03-26 21:54:44 +03:00
|
|
|
return os.popen(command, mode)
|
|
|
|
|
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-03-26 21:54:44 +03:00
|
|
|
def testpid(pid):
|
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 False if pid dead, True if running or not sure"""
|
|
|
|
if pycompat.sysplatform == "OpenVMS":
|
2009-03-26 21:54:44 +03:00
|
|
|
return True
|
|
|
|
try:
|
|
|
|
os.kill(pid, 0)
|
|
|
|
return True
|
2015-06-24 08:20:08 +03:00
|
|
|
except OSError as inst:
|
2009-03-26 21:54:44 +03:00
|
|
|
return inst.errno != errno.ESRCH
|
|
|
|
|
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
|
|
|
|
2011-05-06 17:31:09 +04:00
|
|
|
def explainexit(code):
|
2009-09-21 00:19:18 +04:00
|
|
|
"""return a 2-tuple (desc, code) describing a subprocess status
|
|
|
|
(codes from kill are negative - not os.system/wait encoding)"""
|
|
|
|
if code >= 0:
|
|
|
|
return _("exited with status %d") % code, code
|
|
|
|
return _("killed by signal %d") % -code, -code
|
2009-03-26 21:54:44 +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
|
|
|
|
2009-05-31 01:42:35 +04:00
|
|
|
def isowner(st):
|
|
|
|
"""Return True if the stat object st is from the current user."""
|
2009-03-26 21:54:44 +03:00
|
|
|
return st.st_uid == os.getuid()
|
|
|
|
|
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
|
|
|
|
2011-05-08 22:35:46 +04:00
|
|
|
def findexe(command):
|
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
|
|
|
"""Find executable for command searching like which does.
|
2009-03-26 21:54:44 +03:00
|
|
|
If command is a basename then PATH is searched for command.
|
|
|
|
PATH isn't searched if command is an absolute or relative path.
|
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 command isn't found None is returned."""
|
|
|
|
if pycompat.sysplatform == "OpenVMS":
|
2009-03-26 21:54:44 +03:00
|
|
|
return command
|
|
|
|
|
|
|
|
def findexisting(executable):
|
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
|
|
|
"Will return executable if existing file"
|
2011-11-17 03:55:32 +04:00
|
|
|
if os.path.isfile(executable) and os.access(executable, os.X_OK):
|
2009-03-26 21:54:44 +03:00
|
|
|
return executable
|
|
|
|
return None
|
|
|
|
|
2016-12-17 17:32:50 +03:00
|
|
|
if pycompat.ossep in command:
|
2009-03-26 21:54:44 +03:00
|
|
|
return findexisting(command)
|
|
|
|
|
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 pycompat.sysplatform == "plan9":
|
|
|
|
return findexisting(os.path.join("/bin", command))
|
2012-04-08 23:43:41 +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
|
|
|
for path in encoding.environ.get("PATH", "").split(pycompat.ospathsep):
|
2009-03-26 21:54:44 +03:00
|
|
|
executable = findexisting(os.path.join(path, command))
|
|
|
|
if executable is not None:
|
2011-11-17 03:55:32 +04:00
|
|
|
return executable
|
2009-03-26 21:54:44 +03:00
|
|
|
return 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
|
|
|
|
2011-05-06 17:41:04 +04:00
|
|
|
def setsignalhandler():
|
2009-03-26 21:54:44 +03:00
|
|
|
pass
|
|
|
|
|
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 03:56:29 +03:00
|
|
|
_wantedkinds = {stat.S_IFREG, stat.S_IFLNK}
|
2012-12-01 03:55:07 +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-03-26 21:54:44 +03:00
|
|
|
def statfiles(files):
|
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
|
|
|
"""Stat each file in files. Yield each stat, or None if a file does not
|
|
|
|
exist or has a type we don't care about."""
|
2009-03-26 21:54:44 +03:00
|
|
|
lstat = os.lstat
|
2012-12-01 03:55:07 +04:00
|
|
|
getkind = stat.S_IFMT
|
2009-03-26 21:54:44 +03:00
|
|
|
for nf in files:
|
|
|
|
try:
|
|
|
|
st = lstat(nf)
|
2012-12-01 03:55:07 +04:00
|
|
|
if getkind(st.st_mode) not in _wantedkinds:
|
|
|
|
st = None
|
2015-06-24 08:20:08 +03:00
|
|
|
except OSError as err:
|
2009-03-26 21:54:44 +03:00
|
|
|
if err.errno not in (errno.ENOENT, errno.ENOTDIR):
|
|
|
|
raise
|
|
|
|
st = None
|
|
|
|
yield st
|
|
|
|
|
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-03-26 21:54:44 +03:00
|
|
|
def getuser():
|
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 name of current user"""
|
2017-04-20 22:23:38 +03:00
|
|
|
return pycompat.fsencode(getpass.getuser())
|
2009-03-26 21:54:44 +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
|
|
|
|
2009-03-26 21:54:44 +03:00
|
|
|
def username(uid=None):
|
|
|
|
"""Return the name of the user with the given uid.
|
|
|
|
|
|
|
|
If uid is None, return the name of the current user."""
|
|
|
|
|
|
|
|
if uid is None:
|
|
|
|
uid = os.getuid()
|
|
|
|
try:
|
|
|
|
return pwd.getpwuid(uid)[0]
|
|
|
|
except KeyError:
|
|
|
|
return str(uid)
|
|
|
|
|
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-03-26 21:54:44 +03:00
|
|
|
def groupname(gid=None):
|
|
|
|
"""Return the name of the group with the given gid.
|
|
|
|
|
|
|
|
If gid is None, return the name of the current group."""
|
|
|
|
|
|
|
|
if gid is None:
|
|
|
|
gid = os.getgid()
|
|
|
|
try:
|
|
|
|
return grp.getgrgid(gid)[0]
|
|
|
|
except KeyError:
|
|
|
|
return str(gid)
|
2009-04-10 23:20:25 +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
|
|
|
|
2010-05-10 23:09:48 +04:00
|
|
|
def groupmembers(name):
|
|
|
|
"""Return the list of members of the group with the given
|
|
|
|
name, KeyError if the group does not exist.
|
|
|
|
"""
|
|
|
|
return list(grp.getgrnam(name).gr_mem)
|
|
|
|
|
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-10 23:20:25 +04:00
|
|
|
def spawndetached(args):
|
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 os.spawnvp(os.P_NOWAIT | getattr(os, "P_DETACH", 0), args[0], args)
|
|
|
|
|
2009-04-10 23:20:25 +04:00
|
|
|
|
2010-01-06 23:11:58 +03:00
|
|
|
def gethgcmd():
|
2018-08-17 20:40:14 +03:00
|
|
|
# in case this is called from a Rust binary, the fist element of sys.argv
|
|
|
|
# is entrypoint.py, which is not executable
|
2018-10-23 18:25:50 +03:00
|
|
|
if executionmodel.executedfrombinary:
|
2018-08-17 20:40:14 +03:00
|
|
|
return [sys.executable]
|
2010-01-06 23:11:58 +03:00
|
|
|
return sys.argv[:1]
|
2010-04-27 00:30:40 +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
|
|
|
|
2011-07-22 11:53:15 +04:00
|
|
|
def makedir(path, notindexed):
|
2018-05-23 09:25:25 +03:00
|
|
|
try:
|
|
|
|
os.mkdir(path)
|
|
|
|
except OSError as err:
|
|
|
|
# Spend a little more effort making the error less mysterious in case
|
|
|
|
# there is a broken symlink.
|
|
|
|
if err.errno == errno.ENOENT:
|
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
|
|
|
_checkbrokensymlink(path, "makedir")
|
2018-05-23 09:25:25 +03:00
|
|
|
raise
|
2011-07-22 11:55:46 +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
|
|
|
|
2011-07-22 12:31:56 +04:00
|
|
|
def lookupreg(key, name=None, scope=None):
|
|
|
|
return None
|
2011-07-22 12:35:05 +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
|
|
|
|
2011-07-22 12:35:05 +04:00
|
|
|
def hidewindow():
|
|
|
|
"""Hide current shell window.
|
|
|
|
|
|
|
|
Used to hide the window opened when starting asynchronous
|
|
|
|
child process under Windows, unneeded on other systems.
|
|
|
|
"""
|
|
|
|
pass
|
2011-07-23 14:29:52 +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
|
|
|
|
2011-07-25 16:03:02 +04:00
|
|
|
class cachestat(object):
|
|
|
|
def __init__(self, path):
|
2018-10-18 06:02:13 +03:00
|
|
|
if path is None:
|
|
|
|
self.stat = None
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
self.stat = os.stat(path)
|
|
|
|
except OSError as ex:
|
|
|
|
if ex.errno == errno.ENOENT:
|
|
|
|
self.stat = None
|
|
|
|
else:
|
|
|
|
raise
|
2011-07-25 16:03:02 +04:00
|
|
|
|
2012-01-08 21:15:54 +04:00
|
|
|
__hash__ = object.__hash__
|
|
|
|
|
2011-07-25 16:03:02 +04:00
|
|
|
def __eq__(self, other):
|
|
|
|
try:
|
2018-10-18 06:02:13 +03:00
|
|
|
if self.stat is None or other.stat is None:
|
|
|
|
return self.stat is None and other.stat is None
|
2013-01-19 03:55:16 +04:00
|
|
|
# Only dev, ino, size, mtime and atime are likely to change. Out
|
|
|
|
# of these, we shouldn't compare atime but should compare the
|
|
|
|
# rest. However, one of the other fields changing indicates
|
|
|
|
# something fishy going on, so return False if anything but atime
|
|
|
|
# changes.
|
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.stat.st_mode == other.stat.st_mode
|
|
|
|
and self.stat.st_ino == other.stat.st_ino
|
|
|
|
and self.stat.st_dev == other.stat.st_dev
|
|
|
|
and self.stat.st_nlink == other.stat.st_nlink
|
|
|
|
and self.stat.st_uid == other.stat.st_uid
|
|
|
|
and self.stat.st_gid == other.stat.st_gid
|
|
|
|
and self.stat.st_size == other.stat.st_size
|
|
|
|
and self.stat.st_mtime == other.stat.st_mtime
|
|
|
|
and self.stat.st_ctime == other.stat.st_ctime
|
|
|
|
)
|
2011-07-25 16:03:02 +04:00
|
|
|
except AttributeError:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def __ne__(self, other):
|
|
|
|
return not self == 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
|
|
|
|
2011-07-23 14:29:52 +04:00
|
|
|
def executablepath():
|
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 None # available on Windows only
|
|
|
|
|
2012-12-19 05:15:13 +04:00
|
|
|
|
2013-04-03 22:35:27 +04:00
|
|
|
def statislink(st):
|
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
|
|
|
"""check whether a stat result is a symlink"""
|
2013-04-03 22:35:27 +04:00
|
|
|
return st and stat.S_ISLNK(st.st_mode)
|
|
|
|
|
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-04-03 22:35:27 +04:00
|
|
|
def statisexec(st):
|
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
|
|
|
"""check whether a stat result is an executable file"""
|
2015-06-24 08:30:33 +03:00
|
|
|
return st and (st.st_mode & 0o100 != 0)
|
2014-08-16 07:02:18 +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
|
|
|
|
2015-05-21 02:00:05 +03:00
|
|
|
def poll(fds):
|
|
|
|
"""block until something happens on any file descriptor
|
|
|
|
|
|
|
|
This is a generic helper that will check for any activity
|
|
|
|
(read, write. exception) and return the list of touched files.
|
|
|
|
|
|
|
|
In unsupported cases, it will raise a NotImplementedError"""
|
|
|
|
try:
|
2016-12-22 17:14:13 +03:00
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
res = select.select(fds, fds, fds)
|
|
|
|
break
|
|
|
|
except select.error as inst:
|
|
|
|
if inst.args[0] == errno.EINTR:
|
|
|
|
continue
|
|
|
|
raise
|
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
|
|
|
except ValueError: # out of range file descriptor
|
2015-05-21 02:00:05 +03:00
|
|
|
raise NotImplementedError()
|
|
|
|
return sorted(list(set(sum(res, []))))
|
|
|
|
|
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
|
|
|
|
2014-08-16 07:02:18 +04:00
|
|
|
def readpipe(pipe):
|
|
|
|
"""Read all available data from a pipe."""
|
2014-08-16 21:28:59 +04:00
|
|
|
# We can't fstat() a pipe because Linux will always report 0.
|
|
|
|
# So, we set the pipe to non-blocking mode and read everything
|
|
|
|
# that's available.
|
|
|
|
flags = fcntl.fcntl(pipe, fcntl.F_GETFL)
|
|
|
|
flags |= os.O_NONBLOCK
|
|
|
|
oldflags = fcntl.fcntl(pipe, fcntl.F_SETFL, flags)
|
|
|
|
|
|
|
|
try:
|
|
|
|
chunks = []
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
s = pipe.read()
|
|
|
|
if not s:
|
|
|
|
break
|
|
|
|
chunks.append(s)
|
|
|
|
except IOError:
|
|
|
|
break
|
|
|
|
|
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 "".join(chunks)
|
2014-08-16 21:28:59 +04:00
|
|
|
finally:
|
|
|
|
fcntl.fcntl(pipe, fcntl.F_SETFL, oldflags)
|
2016-05-21 10:52:04 +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
|
|
|
|
2016-05-21 10:52:04 +03:00
|
|
|
def bindunixsocket(sock, path):
|
|
|
|
"""Bind the UNIX domain socket to the specified path"""
|
|
|
|
# use relative path instead of full path at bind() if possible, since
|
|
|
|
# AF_UNIX path has very small length limit (107 chars) on common
|
|
|
|
# platforms (see sys/un.h)
|
|
|
|
dirname, basename = os.path.split(path)
|
|
|
|
bakwdfd = None
|
|
|
|
if dirname:
|
2018-09-05 04:56:29 +03:00
|
|
|
bakwdfd = os.open(".", os.O_DIRECTORY | O_CLOEXEC)
|
2016-05-21 10:52:04 +03:00
|
|
|
os.chdir(dirname)
|
|
|
|
sock.bind(basename)
|
|
|
|
if bakwdfd:
|
|
|
|
os.fchdir(bakwdfd)
|
|
|
|
os.close(bakwdfd)
|
2018-11-29 04:56:15 +03:00
|
|
|
|
|
|
|
|
|
|
|
def _safehasattr(thing, attr):
|
|
|
|
# deferred import to avoid circular import
|
|
|
|
from . import util
|
|
|
|
|
|
|
|
return util.safehasattr(thing, attr)
|
|
|
|
|
|
|
|
|
|
|
|
def syncfile(fp):
|
|
|
|
"""Makes best effort attempt to make sure all contents previously written
|
|
|
|
to the fp is persisted to a permanent storage device."""
|
|
|
|
try:
|
|
|
|
fp.flush()
|
|
|
|
if _safehasattr(fcntl, "F_FULLFSYNC"):
|
|
|
|
# OSX specific. See comments in syncdir for discussion on this topic.
|
|
|
|
fcntl.fcntl(fp.fileno(), fcntl.F_FULLFSYNC)
|
|
|
|
else:
|
|
|
|
os.fsync(fp.fileno())
|
|
|
|
except (OSError, IOError):
|
|
|
|
# do nothing since this is just best effort
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def syncdir(dirpath):
|
|
|
|
"""Makes best effort attempt to make sure previously issued renames where
|
|
|
|
target is a file immediately inside the specified dirpath is persisted
|
|
|
|
to a permanent storage device."""
|
|
|
|
|
|
|
|
# Syncing a file is not as simple as it seems.
|
|
|
|
#
|
|
|
|
# The most common sequence is to sync a file correctly in Unix is `open`,
|
|
|
|
# `fflush`, `fsync`, `close`.
|
|
|
|
#
|
|
|
|
# However, what is the right sequence in case a temporary staging file is
|
|
|
|
# involved? This [LWN article][lwn] lists a sequence of necessary actions.
|
|
|
|
#
|
|
|
|
# 1. create a new temp file (on the same file system!)
|
|
|
|
# 2. write data to the temp file
|
|
|
|
# 3. fsync() the temp file
|
|
|
|
# 4. rename the temp file to the appropriate name
|
|
|
|
# 5. fsync() the containing directory
|
|
|
|
#
|
|
|
|
# While the above step didn't mention flush, it is important to realize
|
|
|
|
# that step 2 implies flush. This is also emphasized by the python
|
|
|
|
# documentation for [os][os]: one should first do `f.flush()`, and then do
|
|
|
|
# `os.fsync(f.fileno())`.
|
|
|
|
#
|
|
|
|
# Performance wise, this [blog article][thunk] points out that the
|
|
|
|
# performance may be affected by other write operations. Here are two of
|
|
|
|
# the many reasons, to help provide an intuitive understanding:
|
|
|
|
#
|
|
|
|
# 1. There is no requirement to prioritize persistence of the file
|
|
|
|
# descriptor with an outstanding fsync call;
|
|
|
|
# 2. Some filesystems require a certain order of data persistence (for
|
|
|
|
# example, to match the order writes were issued).
|
|
|
|
#
|
|
|
|
# There are also platform specific complexities.
|
|
|
|
#
|
|
|
|
# * On [OSX][osx], it is helpful to call fcntl with a particular flag
|
|
|
|
# in addition to calling flush. There is an unresolved
|
|
|
|
# [issue][pythonissue] related to hiding this detail from Python
|
|
|
|
# programmers. In Java, implementation of FileChannel.force was changed
|
|
|
|
# to use fcntl since [JDK-8080589][jdk-rfr].
|
|
|
|
# * On [Windows][msdn], it is not possible to call FlushFileBuffers on a
|
|
|
|
# Directory Handle. And this [svn mailing list thread][svn] shows that
|
|
|
|
# MoveFile does not provide durability guarantee. It may be possible to
|
|
|
|
# get durability by using MOVEFILE_WRITE_THROUGH flag.
|
|
|
|
#
|
|
|
|
# It is important that one does not retry `fsync` on failures, which is a
|
|
|
|
# point that PostgreSQL learned the hard way, now known as [fsyncgate][pg].
|
|
|
|
# The same thread also points out that the sequence of close/re-open/fsync
|
|
|
|
# does not provide the same durability guarantee in the presence of sync
|
|
|
|
# failures.
|
|
|
|
#
|
|
|
|
# [lwn]: https://lwn.net/Articles/457667/
|
|
|
|
# [os]: https://docs.python.org/3/library/os.html
|
|
|
|
# [osx]: https://github.com/untitaker/python-atomicwrites/pull/16/files
|
|
|
|
# [jdk-rfr]: http://mail.openjdk.java.net/pipermail/nio-dev/2015-May/003174.html
|
|
|
|
# [pg]: https://www.postgresql.org/message-id/flat/CAMsr%2BYHh%2B5Oq4xziwwoEfhoTZgr07vdGG%2Bhu%3D1adXx59aTeaoQ%40mail.gmail.com
|
|
|
|
# [thunk]: https://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/
|
|
|
|
# [pythonissue]: https://bugs.python.org/issue11877
|
|
|
|
# [msdn]: https://docs.microsoft.com/en-us/windows/desktop/FileIO/obtaining-a-handle-to-a-directory
|
|
|
|
# [svn]: http://mail-archives.apache.org/mod_mbox/subversion-dev/201506.mbox/%3cCA+t0gk00nz1f+5bpxjNSK5Xnr4rXZx7ywQ_twr5CN6MyZSKw+w@mail.gmail.com%3e
|
|
|
|
try:
|
|
|
|
dirfd = os.open(dirpath, os.O_DIRECTORY)
|
|
|
|
if _safehasattr(fcntl, "F_FULLFSYNC"):
|
|
|
|
# osx specific
|
|
|
|
fcntl.fcntl(dirfd, fcntl.F_FULLFSYNC)
|
|
|
|
else:
|
|
|
|
os.fsync(dirfd)
|
|
|
|
os.close(dirfd)
|
|
|
|
except (OSError, IOError):
|
|
|
|
# do nothing since this is just best effort
|
|
|
|
pass
|