Commit Graph

22 Commits

Author SHA1 Message Date
Augie Fackler
e2774d9258 python3: wrap all uses of <exception>.strerror with strtolocal
Our string literals are bytes, and we mostly want to %-format a
strerror into a one of those literals, so this fixes a ton of issues.
2017-08-22 20:03:07 -04:00
Yuya Nishihara
ba69ca47d4 pathauditor: disable cache of audited paths by default (issue5628)
The initial attempt was to discard cache when appropriate, but it appears
to be error prone. We had to carefully inspect all places where audit() is
called e.g. without actually updating filesystem, before removing files and
directories, etc.

So, this patch disables the cache of audited paths by default, and enables
it only for the following cases:

 - short-lived auditor objects
 - repo.vfs, repo.svfs, and repo.cachevfs, which are managed directories
   and considered sort of append-only (a file/directory would never be
   replaced with a symlink)

There would be more cacheable vfs objects (e.g. mq.queue.opener), but I
decided not to inspect all of them in this patch. We can make them cached
later.

Benchmark result:

- using old clone of http://selenic.com/repo/linux-2.6/ (38319 files)
- on tmpfs
- run HGRCPATH=/dev/null hg up -q --time tip && hg up -q null
- try 4 times and take the last three results

original:
real 7.480 secs (user 1.140+22.760 sys 0.150+1.690)
real 8.010 secs (user 1.070+22.280 sys 0.170+2.120)
real 7.470 secs (user 1.120+22.390 sys 0.120+1.910)

clearcache (the other series):
real 7.680 secs (user 1.120+23.420 sys 0.140+1.970)
real 7.670 secs (user 1.110+23.620 sys 0.130+1.810)
real 7.740 secs (user 1.090+23.510 sys 0.160+1.940)

enable cache only for vfs and svfs (this series):
real 8.730 secs (user 1.500+25.190 sys 0.260+2.260)
real 8.750 secs (user 1.490+25.170 sys 0.250+2.340)
real 9.010 secs (user 1.680+25.340 sys 0.280+2.540)

remove cache function at all (for reference):
real 9.620 secs (user 1.440+27.120 sys 0.250+2.980)
real 9.420 secs (user 1.400+26.940 sys 0.320+3.130)
real 9.760 secs (user 1.530+27.270 sys 0.250+2.970)
2017-07-26 22:10:15 +09:00
Boris Feld
71ca1ed413 vfs: allow to pass more argument to audit
We want to be able to do more precise check when auditing a path depending of
the intend of the file access (eg read versus write). So we now pass the 'mode'
value to 'audit' and update the audit function to accept them.

This will be put to use in the next changeset.
2017-07-11 12:27:58 +02:00
Yuya Nishihara
12efb6fc0b vfs: rename auditvfs to proxyvfs
Since we've removed mustaudit property, auditvfs has no auditing business.
It's just a utility class for vfs wrappers.
2017-07-07 23:40:00 +09:00
FUJIWARA Katsunori
694930365e vfs: add explanation about cost of checkambig=True in corner case 2017-07-04 23:13:47 +09:00
FUJIWARA Katsunori
c8693a0bc7 vfs: replace avoiding ambiguity in abstractvfs.rename with _avoidambig
This centralizes common logic to forcibly avoid file stat ambiguity
into _avoidambig(), which was introduced by previous patch.
2017-07-04 23:13:47 +09:00
FUJIWARA Katsunori
b388e6fb18 vfs: copy if EPERM to avoid file stat ambiguity forcibly at closing
Now, files (to be truncated) are opened with checkambig=True, only if
localrepository caches it.

Therefore, straightforward "copy if EPERM" is always reasonable to
avoid file stat ambiguity at closing.

This patch makes checkambigatclosing close wrapper copy the target
file, and advance mtime on it after renaming, if EPERM. This can avoid
file stat ambiguity, even if the target file is owned by another (see
issue5418 and issue5584 for detail).

This patch factors main logic out instead of changing
checkambigatclosing._checkambig() directly, in order to reuse it.
2017-07-04 23:13:47 +09:00
Pierre-Yves David
100790fbf4 vfs: drop the 'mustaudit' API
There are no remaining users of 'mustaudit' so we can safely drop the API.
External user are unlikely from a quick research so no deprecation is added.
2017-07-02 04:26:42 +02:00
Pierre-Yves David
6da87d469e vfs: simplify path audit disabling in stream clone
The whole 'mustaudit' API is quite complex compared to its actual usage by its
unique user in stream clone.

Instead we add a "auditpath" parameter to 'vfs.__call_'. The stream clone code
then explicitly open files with path auditing disabled.

The 'mustaudit' API will be cleaned up in the next changeset.
2017-07-02 02:28:04 +02:00
Pierre-Yves David
540f21db22 configitems: gather comment related to 'worker.backgroundclosemaxqueue'
Thanks to Yuya for pointing this out.
2017-07-05 00:01:30 +02:00
Pierre-Yves David
83aeb84d41 configitems: register the 'worker.backgroundclosethreadcount' config 2017-06-30 03:46:00 +02:00
Pierre-Yves David
ec7068f984 configitems: register the 'worker.backgroundcloseminfilecount' config 2017-06-30 03:45:59 +02:00
Pierre-Yves David
11b3c8d2af configitems: register the 'worker.backgroundclosemaxqueue' config 2017-06-30 03:45:58 +02:00
Siddharth Agarwal
e0e3b8e4ce filestat: move __init__ to frompath constructor
We're going to add a `fromfp` constructor soon, and this also allows a filestat
object for a non-existent file to be created.
2017-06-10 14:09:54 -07:00
FUJIWARA Katsunori
534d75d626 vfs: create copy at renaming to avoid file stat ambiguity if needed
In order to fix issue5418, 0d920bcb0fd1 made vfs.rename(checkambig=True)
omit advancing mtime of renamed file, if renamed file is owned by
another (EPERM is raised in this case).

But this omission causes rewinding mtime at restoration in such
situation, and makes avoiding file stat ambiguity difficult, because
ExactCacheValidationPlan assumes that mtime should be advanced, if a
file is changed in same ctime.

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan

Ambiguity of file stat also requires issue5584 to be fixed with other
than file stat, but "hash of file", "generation ID" and so on were
already rejected ideas (please see original RFC linked from "Outline
of issue" in ExactCacheValidationPlan page).

This omission occurs:

  - only for non append-only files (dirstate, bookmarks, and phaseroots), and
  - only if previous transaction is rollbacked by another user

The latter means "sharing a repository clone via group permission".
This is reasonable usecase, but not ordinary for many users, IMHO.
"hg rollback" itself has been deprecated since Mercurial 2.7, too.

Therefore, increasing the cost at rollbacking previous transaction
executed by another a little seems reasonable, for avoidance of file
stat ambiguity.

This patch does:

  - create copy of (already renamed) source file, if advancing mtime
    fails for EPERM
  - rename from copied file to destination file, and
  - advance mtime of renamed file, which is now owned by current user

This patch also factors "self.join(src)" out to reduce redundancy.
2017-06-09 12:58:18 +09:00
FUJIWARA Katsunori
f7f00ec91e vfs: factor out "rename and avoid ambiguity" to reuse
This makes subsequent patch simple.
2017-06-09 12:58:18 +09:00
Yuya Nishihara
cbe21a1cc9 osutil: proxy through util (and platform) modules (API)
See the previous commit for why. Marked as API change since osutil.listdir()
seems widely used in third-party extensions.

The win32mbcs extension is updated to wrap both util. and windows. aliases.
2017-04-26 22:26:28 +09:00
Yuya Nishihara
2a7deb97d4 py3: abuse r'' to preserve str-ness of literals passed to __setattr__() 2017-03-26 16:33:12 +09:00
Ryan McElroy
cb1115163c vfs: use tryunlink 2017-03-21 06:50:28 -07:00
Ryan McElroy
a75b679fd2 vfs: add tryunlink method
Thoughout hg code, we see a pattern of attempting to remove a file and then
catching and ignoring any errors due to a missing file in the calling code.
Let's unify this pattern in a single implementation in the vfs layer.
2017-03-21 06:50:28 -07:00
Mads Kiilerich
a936a7f3a7 vfs: use repo.wvfs.unlinkpath 2015-01-14 01:15:26 +01:00
Pierre-Yves David
12f94cda0a vfs: extract 'vfs' class and related code to a new 'vfs' module (API)
The 'scmutil' is growing large (1500+ lines) and 2/5 of it is related to vfs.
We extract the 'vfs' related code in its own module get both module back to a
better scale and clearer contents.

We keep all the references available in 'scmutil' for now as many reference
needs to be updated.
2017-03-01 11:00:12 +01:00