Commit Graph

18 Commits

Author SHA1 Message Date
Durham Goode
19cf6eada4 pathauditor: change parts verification order to be root first
Previously, when we verified the parts of a path in the auditor, we would
validate the deepest directory first, then it's parent, and so on up to the
root. If there happened to be a symlink in the chain, that meant our first check
would likely traverse that symlink.  In some cases that symlink might point to
a network filesystem that is expensive, and therefore this simple check could be
very slow.

The fix is to check the path parts starting at the root and working our way
down.

This has a minor performance difference in that we used to be able to short
circuit from the audit if we reached a directory that had already been checked.
Now we can't, but the cost is N dictionary look ups, where N is the number of
parts in the path, which should be fairly minor.
2016-02-11 17:04:33 -08:00
Pierre-Yves David
4777cbdc66 pathutil: use temporary variables instead of complicated wrapping
The one-lining did not help readability, we get rid of it.
2015-12-03 13:14:20 -08:00
Pierre-Yves David
225db290d0 pathauditor: add a way to skip file system check
We need to be able to skip it when looking at data within the history.
Doing them in all cases leads to buggy behavior like issue4749.
2015-12-03 10:40:19 -08:00
Pierre-Yves David
6e76158146 pathauditor: move file system specific check in their own function
This will make it easy to disable that part when not relevant (eg: auditing
filename for operation in history)
2015-12-03 12:22:48 -08:00
Pierre-Yves David
30913031d4 error: get Abort from 'error' instead of 'util'
The home of 'Abort' is 'error' not 'util' however, a lot of code seems to be
confused about that and gives all the credit to 'util' instead of the
hardworking 'error'. In a spirit of equity, we break the cycle of injustice and
give back to 'error' the respect it deserves. And screw that 'util' poser.

For great justice.
2015-10-08 12:55:45 -07:00
Gregory Szorc
d3199991df pathutil: use absolute_import 2015-08-08 19:45:15 -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
Augie Fackler
8132db78d0 pathutil: demote two local functions to just be forwards
We retain the forwards because it helps code be more ignorant of
implementation details, but use forwards instead of our own method
definitions since we don't need any truly custom behavior for now.
2015-05-26 14:41:00 -04:00
Augie Fackler
98072a6fc9 pathutil: restate dirname and join as forwards to posixpath
I've done this as its own step so that it's easy to see that the
posixpath implementations pass the doctests in this package. In a
future patch I'll just make these pure forwards of the methods so that
things using pathutil can be oblivious to the posix nature of these
functions.
2015-05-26 14:30:48 -04:00
Durham Goode
43bd136581 pathutil: add dirname and join functions
This adds dirname and join functions to pathutil which are explicitly for
handling '/' delimited paths. The implementations are basically copy paste from
python's posix os.path.dirname and os.path.join functions.
2015-05-22 12:47:18 -07:00
Matt Mackall
a2d7016ad6 canonpath: fix infinite recursion 2015-05-12 19:40:45 -05:00
Matt Harbison
9085702dae pathutil: hint if a path is root relative instead of cwd relative (issue4663)
Given that this path is going to abort, it seems OK to spend the time to do an
alternate lookup to better inform the user.  The path returned by util.pathto()
ends with '/' at least in some cases, so os.path.relpath() is used instead,
which requires python 2.6.
2015-05-11 21:26:13 -04:00
Matt Mackall
0826b8e884 merge with stable 2014-12-18 16:41:59 -06:00
Matt Mackall
8b83dfc480 pathauditor: check for Windows shortname aliases 2014-12-18 14:18:28 -06:00
Augie Fackler
13206234f4 pathauditor: check for codepoints ignored on OS X 2014-12-16 13:08:17 -05:00
Mads Kiilerich
523c87c1fe spelling: fixes from proofreading of spell checker issues 2014-04-17 22:47:38 +02:00
FUJIWARA Katsunori
85d651396d subrepo: normalize path in the specific way for problematic encodings
Before this patch, "reporelpath()" uses "rstrip(os.sep)" to trim
"os.sep" at the end of "parent.root" path.

But it doesn't work correctly with some problematic encodings on
Windows, because some multi-byte characters in such encodings contain
'\\' (0x5c) as the tail byte of them.

In such cases, "reporelpath()" leaves unexpected '\\' at the beginning
of the path returned to callers.

"lcalrepository.root" seems not to have tail "os.sep", because it is
always normalized by "os.path.realpath()" in "vfs.__init__()", but in
fact it has tail "os.sep", if it is a root (of the drive): path
normalization trims tail "os.sep" off "/foo/bar/", but doesn't trim
one off "/".

So, just avoiding "rstrip(os.sep)" in "reporelpath()" causes
regression around issue3033 fixed by e3dfde137fa5.

This patch introduces "pathutil.normasprefix" to normalize specified
path in the specific way for problematic encodings without regression
around issue3033.
2014-05-08 19:03:00 +09:00
Augie Fackler
213fff305a pathutil: tease out a new library to break an import cycle from canonpath use 2013-11-06 18:19:04 -05:00