Commit Graph

59 Commits

Author SHA1 Message Date
Augie Fackler
f47ca49ac7 osutil: stop using strcpy
strcpy is a security vulnerability masquerading as a utility
function. Replace it with memcpy since we know how much to copy
anyway.
2016-03-19 20:02:19 -04:00
Yuya Nishihara
ce2c3d9c16 osutil: disable compilation of recvfds() on unsupported platforms
It appears that Solaris doesn't provide CMSG_LEN(), msg_control, etc. As
recvfds() is only necessary for chg, this patch just drops it if CMSG_LEN
isn't defined, which is the same workaround as Python 3.x.

https://hg.python.org/cpython/rev/c64216addd7f#l7.33
2016-02-02 20:56:48 +09:00
Matt Mackall
4343a7194d mac: ignore resource fork when checking file sizes
Some evil evil awful tool adds resource forks to files it's comparing.
Our Mac-specific code to do bulk stats was accidentally using "total
size" which includes those forks in the file size, causing them to be
reported as modified. This changes it to only care about the normal
data size and thus agree with what Mercurial's expecting.
2016-01-14 12:37:15 -06:00
Yuya Nishihara
1172aa7cd7 osutil: implement recvmsg() of SCM_RIGHTS for chg command server
It will be used to attach client's stdio files to a background chg command
server.

The socket module of Python 2.x doesn't provide recvmsg(). This could be
implemented by using ctypes, but it would be less portable than the C version
because the handling of socket ancillary data heavily depends on preprocessor.
Also, some length fields are wrongly typed in the Linux kernel.
2015-12-17 23:41:46 +09:00
Bryan O'Sullivan
f5b0cc2242 osutil: make statfiles check for interrupts periodically
This is a simpler and faster fix for issue4878 than the contortions
performed in dd36f84bd784.
2015-11-17 13:47:14 -08:00
Bryan O'Sullivan
d04584822f osutil: don't leak on statfiles error
Found using the power of the mighty eyeball.
2015-11-17 13:43:09 -08:00
Siddharth Agarwal
45755aa70f osutil: mark end of string with null char, not 0
Noticed this while working on other stuff in the area.
2015-03-25 16:21:58 -07:00
Siddharth Agarwal
886bf50396 osutil: use getdirentriesattr on OS X if possible
This is a significant win for large repositories on OS X, especially with a
cold cache. Unfortunately we need to keep the lstat-based implementation around
for two reasons:

- Not all filesystems support this call.
- There's an edge case in which it's best to fall back to avoid a retry loop.
  More about this in the comments.

The below tests are all performed on a Mac with an SSD running OS X 10.9, on a
repository with over 200k files. The results are best of 5 with simulated
best-effort conditions.

The gains with a hot cache are pretty impressive: 'hg status' goes from 5.18
seconds to 3.79 seconds.

However, a repository that large will probably already be using something like
hgwatchman [1], which helps much more (for this repo, 'hg status' with
hgwatchman is approximately 1 second). Where this really helps is when the
cache is cold [2]: hg status goes from 31.0 seconds to 9.66.

See http://lists.apple.com/archives/filesystem-dev/2014/Dec/msg00002.html for
some more discussion about this function.

This is based on a patch by Sean Farley <sean@farley.io>.

[1] https://bitbucket.org/facebook/hgwatchman

[2] There appears to be no easy way to clear the file cache (aka "vnodes") on
OS X short of rebooting. purge(8) purportedly does that but in my testing had
little effect. The workaround I came up with was to assume that vnode eviction
was LRU, make sure the kern.maxvnodes sysctl is smaller than the size of the
repository, then make sure we'd always miss the cache by running 'hg status' in
another clone of the repository before running it in the test repository.
2015-03-25 15:55:31 -07:00
Siddharth Agarwal
2af765a245 osutil._listdir: rename to _listdir_stat
In upcoming patches we'll add another implementation of listdir on OS X. That
implementation will have to fall back to this one under some circumstances,
though. We'll make _listdir be able to detect those circumstances and use the
right function as appropriate.
2015-03-25 16:43:29 -07:00
Augie Fackler
4912d4ca49 osutil: fix memory leak of PyBytes of path in statfiles
Spotted with cpychecker.
2015-01-27 10:17:16 -05:00
Augie Fackler
b15ba92295 osutil: fix leak of stat in makestat when Py_BuildValue fails
Spotted with cpychecker.
2015-01-27 10:14:23 -05:00
Augie Fackler
7d0895a2f0 osutil.c: clean up space before a tab 2015-01-27 10:12:55 -05:00
Bryan O'Sullivan
48cad1b73b osutil: tab damage, how i hate thee 2012-12-03 13:17:01 -08:00
Bryan O'Sullivan
58c82f12c9 osutil: write a C implementation of statfiles for unix
This makes a big difference to performance.

In a clean working directory containing 170,000 files, performance of
"hg --time diff" improves from 2.38 seconds to 1.69.
2012-12-03 12:40:24 -08:00
Bryan O'Sullivan
7be204f3cf osutil: fix tab damage 2012-11-30 17:40:11 -08:00
Bryan O'Sullivan
6b3dd5248e osutil: factor out creation and init of listdir_stat 2012-11-30 15:55:09 -08:00
Matt Mackall
1af38adeb7 osutil: handle deletion race with readdir/stat (issue3463) 2012-05-18 14:34:33 -05:00
Matt Mackall
1071a1b580 merge with stable 2011-09-14 14:37:10 -05:00
Steve Streeting
6a5c8744b6 osutil: avoid accidentally destroying the True object in isgui (issue2937)
Needed to use 'Py_RETURN_TRUE' instead of 'return Py_True' to avoid
reference count errors which would randomly crash the Python
executable during merge. This only happened when you had something
configured in merge-tools and the merge was large enough.
2011-09-08 11:34:59 +01:00
Matt Mackall
21b00826e8 osutil: emulate os.listdir's OSError for long names (issue2898) 2011-07-13 16:58:51 -05:00
Dan Villiom Podlaski Christiansen
ecb9e72af1 osutil: replace #import with #include, and add a check for it 2011-03-23 23:05:32 +01:00
Matt Mackall
b156bda724 osutil: fix up check-code issues 2011-03-23 09:41:58 -05:00
Dan Villiom Podlaski Christiansen
9dfabab3ba util: add Mac-specific check whether we're in a GUI session (issue2553)
The previous test assumed that 'os.name' was "mac" on Mac OS X. This
is not the case; 'mac' was classic Mac OS, whereas Mac OS X has 'os.name'
be 'posix'.

Please note that this change will break Mercurial on hypothetical
non-Mac OS X deployments of Darwin.

Credit to Brodie Rao for thinking of CGSessionCopyCurrentDictionary()
and Kevin Bullock for testing.
2011-03-23 09:43:34 +01:00
Martin Geisler
a76e121863 backout of e4cb9628354c
Matt and a majority of crew did not like this approach.
2011-01-27 11:15:08 +01:00
Martin Geisler
d23e1973c2 specify C indention style using Emacs file local variables 2011-01-26 12:05:01 +01:00
Adrian Buehlmann
2226216a7c osutil: treat open modes 'w' and 'a' as 'w+' and 'a+' in posixfile
to work around http://support.microsoft.com/kb/899149.

Also, Microsoft's documentation of the CreateFile Windows API says (quote):

  When an application creates a file across a network, it is better to use
  GENERIC_READ | GENERIC_WRITE for dwDesiredAccess than to use
  GENERIC_WRITE alone. The resulting code is faster, because the
  redirector can use the cache manager and send fewer SMBs with more data.
  This combination also avoids an issue where writing to a file across a
  network can occasionally return ERROR_ACCESS_DENIED.
2011-01-15 23:54:01 +01:00
Renato Cunha
29e7db1052 osutil.c: Support for py3k added.
This patch adds support for py3k in osutil.c. This is accomplished by including
a header file responsible for abstracting the API differences between python 2
and python 3.

listdir_stat_type is also changed in the following way: A previous call to
PyObject_HEAD_INIT is substituted to a call to PyVarObject_HEAD_INIT, which
makes the object buildable in both python 2.x and 3.x without weird warnings.

After testing on windows, some modifications were also made in the posixfile
function, as it calls PyFile_FromFile and PyFile_SetBufSize, which are gone in
py3k. In py3k the PyFile_* API is, actually a wrapper over the io module, and
code has been adapted accordingly to fit py3k.
2010-06-15 19:49:56 -03:00
Matt Mackall
8d99be19f0 many, many trivial check-code fixups 2010-01-25 00:05:27 -06:00
Sebastien Binet
44975f5f1e osutil: fix compilation with -ansi 2009-08-14 11:18:23 +02:00
Brendan Cully
9c33729b44 Merge with crew-stable 2009-06-06 13:37:41 -07:00
Arne Babenhauserheide
5ded475334 Some platforms lack the PATH_MAX definition (eg. GNU/Hurd).
Thanks to ronny for making it cleaner.
2009-06-05 15:08:45 +02:00
Patrick Mezard
c51f73163e osutil: silence uninitialized variable warning 2009-05-24 16:27:50 +02:00
Bryan O'Sullivan
3054118009 Windows: improve performance via buffered I/O
The posixfile_nt code hits the win32 file API directly, which
essentially amounts to performing a system call for every read and
write. This is slow.

We add a C extension that lets us use a Python file object instead,
but preserve our desired POSIX-like semantics (the ability to rename
or delete a file that is being accessed).

If the C extension is not available (e.g. in a VPS environment
without a compiler), we fall back to the posixfile_nt code.
2009-05-08 15:52:26 -07:00
Thomas Arendsen Hein
8999e196bc Some additional space/tab cleanups 2008-10-20 15:19:05 +02:00
Brendan Cully
44b5949ce4 _listdir only uses dfd if AT_SYMLINK_NOFOLLOW is defined 2008-10-18 11:43:45 -07:00
Benoit Boissinot
1c8e168451 osutil.c: refactor argument parsing, allow skip=None being passed 2008-10-15 14:06:46 +02:00
Petr Kodl
6d8f8227f9 Improve error handling in osutil.c
1) In posix part set error when path is too long so instead of

SystemError: error returned without exception set

it will raise

ValueError: path too long

2) In Win32 part replace generic

PyErr_SetExcFromWindowsErrWithFilename

by

PyErr_SetFromWindowsErrWithFilename

The exception returned is WinError(based on OSError) and
some rudimentary errno translation is performed from Windows error range
to errno module friendly range so errors like ENOENT can be handled via symbolic
constant and consistently between Win32 and Posix.
2008-10-01 08:41:18 -04:00
Petr Kodl
09cc67de2c osutil: implementation for Win32
Use information provided by FindFile... Win32 calls
to generate stat information without lstat call per file.
rwx bits in st_mode are ignored as they are not stored in Win32 fs
and Mercurial does not use them
Unicode path / path names over _MAX_PATH are intentionally not supported.
2008-09-14 09:57:33 -04:00
Matt Mackall
2d47031d0d listdir: add support for aborting if a certain path is found
This lets us bail out early if we find '.hg', letting us skip sorting
and bisecting for it.
2008-09-13 10:46:47 -05:00
Matt Mackall
c0ccecefce osutil: fix some braindamage
- entkind returns -1 on failure
- compile if AT_SYMLINK_NOFOLLOW is missing
- avoid fullpath overflow
2008-09-13 10:44:44 -05:00
Matt Mackall
a1338aa911 osutil: major listdir cleanup 2008-09-12 15:11:02 -05:00
Benoit Boissinot
dd432a82af osutil: proper error checking and reporting 2008-09-10 22:37:07 +02:00
Bryan O'Sullivan
6a52ab5621 osutil: use fdopendir instead of dirfd 2007-10-15 12:57:01 -07:00
Matt Mackall
6983b23f64 osutil: improve portability
- manually inline mode_to_kind
- remove unused alloca include
- remove fstatat and associated bits

It's not obvious that there's an advantage to using fstatat in terms
of performance. The race-avoidance properties of fstatat aren't
terribly useful to us either. So best to avoid it until we figure out
how to use it portably.
2007-10-11 17:46:06 -05:00
Bryan O'Sullivan
69513180ef osutil: Solaris build fix 2007-10-09 08:39:37 -07:00
Bryan O'Sullivan
f32d9d204f Fix build error with Sun C compiler. 2007-10-08 22:45:48 -07:00
Alexis S. L. Carvalho
a6ace30eb5 osutil.c: use strncpy instead of strncat 2007-10-08 21:37:25 -03:00
Matt Mackall
1a6c764cc5 osutil: more tidying
- do_stat -> keep_stat
- all_kinds -> !need_stat
- simplify main error logic
- reorder declarations
2007-10-08 18:47:21 -05:00
Matt Mackall
fb0cad4f74 osutil: move file list loop to its own function 2007-10-08 18:47:18 -05:00
Matt Mackall
cc38448e9d osutil: simplify DT_REG support 2007-10-08 18:47:17 -05:00