Commit Graph

132 Commits

Author SHA1 Message Date
Augie Fackler
f33ab87734 posix: replace superfluous pass statement with explicit return 2017-09-30 07:45:18 -04:00
Augie Fackler
d68f01169b posix: always pass a native str to unicodedata.normalize's first arg 2017-09-15 19:44:32 -04:00
Augie Fackler
e4d2f96bbd posix: use slicing to grab a single byte out of a bytes in HFS+ normcase code 2017-09-15 19:44:05 -04:00
Augie Fackler
e6768c401f posix: fix HFS+ normcase doctest to produce valid bytes literals in Python 3
We were previously getting lucky on Python 2.
2017-09-15 19:43:02 -04:00
Yuya Nishihara
a71f259bd2 doctest: bulk-replace string literals with b'' for Python 3
Our code transformer can't rewrite string literals in docstrings, and I
don't want to make the transformer more complex.
2017-09-03 14:32:11 +09:00
Jun Wu
a0e5a4defb ssh: quote parameters using shellquote (SEC)
This patch uses shellquote to quote ssh parameters more strictly to avoid
shell injection.
2017-08-04 23:54:12 -07:00
Augie Fackler
5f2d0af8a2 ssh: ban any username@host or host that starts with - (SEC)
This paranoia probably isn't required, but it can't hurt either.
2017-08-04 14:00:03 -04:00
Koen Van Hoof
587e5d1c67 chmod: create a new file when flags are set on a hardlinked file
For performance reasons we have several repositories where the files in the working
directory of 1 repo are hardlinks to the files of the other repo
When an update in one repo results in a chmod of a such a file, the hardlink
has to be deleted and replaced by a regular file to make sure that the change
does not happen in the other repo
2017-04-26 16:05:22 +02:00
Augie Fackler
542631c0ed checklink: degrade gracefully on posix when fs is readonly (issue5511)
In the unlucky case, checklink tries to make a new file for the
symlink test to target. If the filesystem is readonly (perhaps due to
permissions in a repo owned by someone else) we just report the
filesystem as not supporting symlinks, since the user probably can't
write anyway.
2017-05-21 18:36:28 -04:00
Martin von Zweigbergk
c3406ac3db cleanup: use set literals
We no longer support Python 2.6, so we can now use set literals.
2017-02-10 16:56:29 -08:00
Pulkit Goyal
cb5518387e py3: make posix.getuser return a bytes 2017-04-21 00:53:38 +05:30
Ryan McElroy
4456f7562c util: unify unlinkpath
Previously, there were two slightly different versions of unlinkpath between
windows and posix, but these differences were eliminated in previous patches.
Now we can unify these two code paths inside of the util module.
2017-03-21 06:50:28 -07:00
Ryan McElroy
cf50c1b95b posix: use local reference to removedirs
We have a local reference to os.removedirs in module scope, but we still used
os.removedirs inside functions. This changes util to use the local reference,
which will pave the way for combining duplicated code in future patches.
2017-03-21 06:50:28 -07:00
Ryan McElroy
9eb9d0168b posix: use local reference to unlink
We have a local reference to os.unlink in module scope, but we still used
os.unlink inside functions. This changes util to use the local reference,
which will pave the way for combining duplicated code in future patches.
2017-03-21 06:50:28 -07:00
Augie Fackler
297b49fbca posix: tiptoe around tempfile module more delicately
Some of the values inside the tempfile calls here are str on Python 3,
so we've got to pass str in. Use fsdecode to work around the issue.
2017-03-19 01:06:47 -04:00
Augie Fackler
e5b22f1ea6 posix: use open() instead of file() 2017-03-19 01:05:48 -04:00
Pulkit Goyal
03903626e4 py3: make the regular expression bytes to prevent TypeError 2017-03-17 05:10:58 +05:30
Augie Fackler
067ebafd12 merge with stable 2017-01-04 14:52:59 -05:00
Yuya Nishihara
c175ab72eb posix: make poll() restart on interruption by signal (issue5452)
select() is a notable example of syscalls which may fail with EINTR. If we
had a SIGWINCH handler installed, ssh would crash when the terminal window
was resized. This patch fixes the problem.
2016-12-22 23:14:13 +09:00
Yuya Nishihara
9531323bdb chgserver: extract utility to bind unix domain socket to long path
This is common problem of using sockaddr_un.
2016-05-21 16:52:04 +09:00
Pulkit Goyal
d35cffe17d py3: replace sys.platform with pycompat.sysplatform (part 2 of 2) 2016-12-19 02:26:41 +05:30
Pulkit Goyal
8edc9540ee py3: replace sys.platform with pycompat.sysplatform (part 1 of 2)
sys.platform returns unicode on python 3 world. Our code base has most of the
things bytes because of the transformer. So we have a bytes version of this as
pycompat.sysplatform. This series of 2 patches replaces occurences of
sys.platform with pycompat.sysplatform.
2016-12-19 02:15:24 +05:30
Pulkit Goyal
f1c1938039 py3: replace os.environ with encoding.environ (part 1 of 5)
os.environ is a dictionary which has string elements on Python 3. We have
encoding.environ which take care of all these things. This is the first patch
of 5 patch series which tend to replace the occurences of os.environ with
encoding.environ as using os.environ will result in unusual behaviour.
2016-12-18 01:34:41 +05:30
Pulkit Goyal
a7d1fd0177 py3: replace os.sep with pycompat.ossep (part 2 of 4)
This part also replaces some chunks of os.sep with pycompat.ossep.
2016-12-17 20:02:50 +05:30
Pulkit Goyal
851ae37944 py3: replace os.pathsep with pycompat.ospathsep
os.pathsep returns unicode on Python 3. We already have pycompat.ospathsep
which return bytes on Python 3. This patch replaces all the occurrences of
os.pathsep in the codebase (excluding tests) to pycompat.ospathsep.
2016-12-17 19:47:17 +05:30
Martijn Pieters
ca91b8fcf4 posix: give the cached symlink a real target
The NamedTemporaryFile file is cleared up so checklink ends up as a dangling
symlink, causing cp -r in tests to complain on both Solaris and OS X. Use
a permanent file instead when there is a .hg/cache directory.
2016-11-30 16:39:36 +00:00
Mads Kiilerich
155cddd3c3 posix: give checklink a fast path that cache the check file and is read only
util.checklink would create a symlink and remove it again. That would sometimes
happen multiple times. Write operations are relatively expensive and give disk
tear and noise for applications monitoring file system activity.

Instead of creating a symlink and deleting it again, just create it once and
leave it in .hg/cache/check-link . If the file exists, just verify that
os.islink reports true. We will assume that this check is as good as symlink
creation not failing.

Note: The symlink left in .hg/cache has to resolve to a file - otherwise 'make
dist' will fail ...

test-symlink-os-yes-fs-no.py does some monkey patching to simulate a platform
without symlink support. The slightly different testing method requires
additional monkeying.
2015-01-14 01:15:26 +01:00
Mads Kiilerich
5363640334 posix: move checklink test file to .hg/cache
This avoids unnecessary churn in the working directory.

It is not necessarily a fully valid assumption that .hg/cache is on the same
filesystem as the working directory, but I think it is an acceptable
approximation. It could also be the case that different parts of the working
directory is on different mount points so checking in the root folder could
also be wrong.
2016-11-17 12:59:36 +01:00
Mads Kiilerich
d799de0c4b 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 01:15:26 +01:00
Mads Kiilerich
bd322d7a0b posix: simplify checkexec check
Use a slightly simpler logic that in some cases can avoid an unnecessary chmod
and stat.

Instead of flipping the X bits, make it more clear that we rely on no X bits
being set on initial file creation, and that at least some of them stick after
they all have been set.
2015-01-14 01:15:26 +01:00
Mads Kiilerich
b18ca0ff60 posix: move checkexec test file to .hg/cache
This avoids unnecessary churn in the working directory.

It is not necessarily a fully valid assumption that .hg/cache is on the same
filesystem as the working directory, but I think it is an acceptable
approximation. It could also be the case that different parts of the working
directory is on different mount points so checking in the root folder could
also be wrong.
2016-11-17 12:59:36 +01:00
Yuya Nishihara
52e59de51c scmutil: move util.termwidth()
I'm going to get rid of sys.stderr|out|in references from posix.termwidth().
In order to do that, termwidth() needs to take a ui, but functions in util.py
shouldn't depend on a ui object. So moves termwidth() to scmutil.py.
2016-10-20 21:38:44 +09:00
Matt Mackall
902e6988c4 mac: fix percent-encoding of non-utf-8 characters (issue4999) 2015-12-12 21:36:21 -06:00
Yuya Nishihara
32e4d29ecb posix: remove unixdomainserver class
It's no longer used since the removal of the inotify extension.
2015-11-21 16:21:52 +09:00
Augie Fackler
85e62f1eda posix: work around "posix" systems without os.link available (issue4974)
Some platforms (see bug, notably a terminal emulator on Android) ship
with os.link removed from Python to try and cater to other tools that
expect os.link to exist iff hardlinks are supported on that
platform. As a workaround for this madness, include a fallback path
for when we're on a "posix" platform but lack os.link.
2015-12-04 15:59:46 -05:00
Matt Mackall
0a9df707c8 merge with stable 2015-11-11 15:08:08 -06:00
Matt Mackall
2dd39095d7 posix: fix test-permissions regression 2015-11-09 15:53:11 -06:00
Matt Mackall
8b9a3d960f posix: retry on symlink race in checklink
Multiple threads might attempt to check links with the same temporary
name. This would cause one side to get an EEXIST error and wrongly
fail the support check. Here, we simply retry if our temporary name
exists.
2015-11-06 15:23:10 -06:00
Matt Mackall
14c5bb7714 merge with stable 2015-11-09 12:49:21 -06:00
Matt Mackall
001845ef91 posix: use getutf8char to handle OS X filename percent-escaping
This replaces an open-coded utf-8 parser that was ignoring subtle issues
like overlong encodings.
2015-11-05 17:09:00 -06:00
timeless@mozdev.org
180d1578ac posix: shellquote do not require quoting for "+" (issue4818) 2015-09-04 11:15:02 -04:00
Gregory Szorc
104f53e8ae posix: use absolute_import 2015-08-08 19:56:58 -07:00
Gregory Szorc
5380dea2a7 global: mass rewrite to use modern exception syntax
Python 2.6 introduced the "except type as instance" syntax, replacing
the "except type, instance" syntax that came before. Python 3 dropped
support for the latter syntax. Since we no longer support Python 2.4 or
2.5, we have no need to continue supporting the "except type, instance".

This patch mass rewrites the exception syntax to be Python 2.6+ and
Python 3 compatible.

This patch was produced by running `2to3 -f except -w -n .`.
2015-06-23 22:20:08 -07:00
Gregory Szorc
3aa1c73868 global: mass rewrite to use modern octal syntax
Python 2.6 introduced a new octal syntax: "0oXXX", replacing "0XXX". The
old syntax is not recognized in Python 3 and will result in a parse
error.

Mass rewrite all instances of the old octal syntax to the new syntax.

This patch was generated by `2to3 -f numliterals -w -n .` and the diff
was selectively recorded to exclude changes to "<N>l" syntax conversion,
which will be handled separately.
2015-06-23 22:30:33 -07:00
Pierre-Yves David
6fec33b555 util: add a simple poll utility
We'll use it to detect when a sshpeer have server output to be displayed.

The implementation is super basic because all case support is not the focus of
this series.
2015-05-20 18:00:05 -05:00
FUJIWARA Katsunori
d376c990a1 util: add removedirs as platform depending function
According to 6b1369445b7b introducing "windows._removedirs()":

    If a hg repository including working directory is a reparse point
    (directory symlinked or a junction point), then using
    os.removedirs will remove the reparse point erroneously.

"windows._removedirs()" should be used instead of "os.removedirs()" on
Windows.

This patch adds "removedirs" as platform depending function to replace
"os.removedirs()" invocations for portability and safety
2015-04-11 00:47:09 +09:00
Siddharth Agarwal
1d374c9821 cygwin: define normcase spec and fallback
These will be used in upcoming patches to efficiently create a dirstate
foldmap.

The Cygwin normcase behavior is more complicated than just a simple lowercasing
or uppercasing. That's why we specify 'other'.
2015-04-01 00:29:22 -07:00
Siddharth Agarwal
fdd75c8724 darwin: define normcase spec and fallback
These will be used in upcoming patches to efficiently create a dirstate
foldmap.
2015-03-31 23:30:19 -07:00
Siddharth Agarwal
180770be60 posix: define normcase spec and fallback
These will be used in upcoming patches to efficiently create a dirstate
foldmap.
2015-04-01 00:26:07 -07:00
Yuya Nishihara
28b8cb187f shellquote: fix missing quotes for empty string
"hg kdiff3 -rREV" did not work because 72640182118e and 295ba4ee1d13 failed
to handle empty argument.
2015-02-11 19:57:07 +09:00