Commit Graph

33 Commits

Author SHA1 Message Date
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
Matt Mackall
dafe26ed0b osutils: pull file stat loop into its own function 2007-10-08 18:47:16 -05:00
Matt Mackall
20936fe972 osutil: fold stat paths together
- simplify st/py_st logic
- use stp to point to stat buffer
- combine stat paths
2007-10-08 18:47:15 -05:00
Matt Mackall
65e8ee71fa osutil: more cleanups
- eliminate a level of nesting
- untab targets of gotos
2007-10-08 18:47:14 -05:00
Matt Mackall
50cce1cc95 osutil: eliminate alloca call
- make full_path a PATH_MAX + epsilon local buffer
- use strncpy and strncat
2007-10-08 18:47:12 -05:00
Matt Mackall
638a3ac761 osutil: cleanups
- use tabs
- eliminate old-style function pointer calls
- eliminate weird scoping
- eliminate assignment-in-iff
- use !foo rather than foo == NULL
2007-10-08 18:47:06 -05:00
Giorgos Keramidas
a1efeccfd8 osutil.c: style fix - delete trailing end-of-line spaces 2007-10-07 21:56:36 +03:00
Alexis S. L. Carvalho
f77b38c731 osutil.c: use readdir instead of readdir64
Some systems (e.g. *BSD) don't have a readdir64 function - the regular
readdir already uses 64-bit types.

On other systems (Linux, Solaris, ...), if Python was compiled with large
file support, Python.h will define _LARGEFILE_SOURCE and _FILE_OFFSET_BITS=64,
so that any call to readdir will actually be a call to readdir64.  If Python
was not compiled with large file support, we probably don't want to define
these macros to avoid ABI problems.
2007-10-06 14:14:11 -03:00
Alexis S. L. Carvalho
f65110708a osutil.c: include Python.h before the other headers
This is recommended by the Python documentation, since Python.h defines
some constants.
2007-10-06 14:14:11 -03:00
Bryan O'Sullivan
e317f81ab3 Add osutil module, containing a listdir function.
This is similar to os.listdir, only it returns a sorted list of tuples.
2007-10-05 15:01:06 -07:00