At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 3845
revision-id: [EMAIL PROTECTED]
parent: [EMAIL PROTECTED]
parent: [EMAIL PROTECTED]
committer: Canonical.com Patch Queue Manager <[EMAIL PROTECTED]>
branch nick: +trunk
timestamp: Fri 2008-11-21 04:44:50 +0000
message:
(mbp) SunOS fixes to readdir_pyx
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/_readdir_pyx.pyx readdir.pyx-20060609152855-rm6v321vuaqyh9tu-1
------------------------------------------------------------
revno: 3841.1.5
revision-id: [EMAIL PROTECTED]
parent: [EMAIL PROTECTED]
committer: Martin Pool <[EMAIL PROTECTED]>
branch nick: 297381-readdir
timestamp: Fri 2008-11-21 15:06:25 +1100
message:
Review cleanups on readdir
modified:
bzrlib/_readdir_pyx.pyx
readdir.pyx-20060609152855-rm6v321vuaqyh9tu-1
------------------------------------------------------------
revno: 3841.1.4
revision-id: [EMAIL PROTECTED]
parent: [EMAIL PROTECTED]
committer: Martin Pool <[EMAIL PROTECTED]>
branch nick: 297381-readdir
timestamp: Thu 2008-11-20 15:45:01 +1100
message:
Use open/fchdir rather than getcwd/chdir to save and restore directory
location
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/_readdir_pyx.pyx
readdir.pyx-20060609152855-rm6v321vuaqyh9tu-1
=== modified file 'NEWS'
--- a/NEWS 2008-11-21 00:53:02 +0000
+++ b/NEWS 2008-11-21 04:44:50 +0000
@@ -31,7 +31,9 @@
(Martin Pool, #289148)
* Don't call the system ``chdir()`` with an empty path. Sun OS seems
- to give an error in that case. (John Arbash Meinel, #297831)
+ to give an error in that case. Also, don't count on ``getcwd()``
+ being able to allocate a new buffer, which is a gnu extension.
+ (John Arbash Meinel, Martin Pool, Harry Hirsch, #297831)
* PermissionDenied errors from smart servers no longer cause
âPermissionDenied: "None"â on the client.
=== modified file 'bzrlib/_readdir_pyx.pyx'
--- a/bzrlib/_readdir_pyx.pyx 2008-11-20 04:17:17 +0000
+++ b/bzrlib/_readdir_pyx.pyx 2008-11-21 04:06:25 +0000
@@ -36,6 +36,8 @@
cdef extern from 'unistd.h':
int chdir(char *path)
+ int close(int fd)
+ int fchdir(int fd)
char *getcwd(char *, int size)
cdef extern from 'stdlib.h':
@@ -49,6 +51,7 @@
ctypedef long time_t
ctypedef unsigned long ino_t
ctypedef unsigned long long off_t
+ ctypedef int mode_t
cdef extern from 'sys/stat.h':
@@ -69,6 +72,11 @@
int S_ISSOCK(int mode)
+cdef extern from 'fcntl.h':
+ int O_RDONLY
+ int open(char *pathname, int flags, mode_t mode)
+
+
cdef extern from 'Python.h':
char * PyString_AS_STRING(object)
ctypedef int Py_ssize_t # Required for older pyrex versions
@@ -279,14 +287,23 @@
cdef char *name
cdef int stat_result
cdef _Stat statvalue
- cdef char *cwd
global errno
+ cdef int orig_dir_fd
- cwd = getcwd(NULL, 0)
- if path != "":
- # Avoid chdir('') because it causes problems on Sun OS
+ # Avoid chdir('') because it causes problems on Sun OS, and avoid this if
+ # staying in .
+ if path != "" and path != '.':
+ # we change into the requested directory before reading, and back at
the
+ # end, because that turns out to make the stat calls measurably faster
than
+ # passing full paths every time.
+ orig_dir_fd = open(".", O_RDONLY, 0)
+ if orig_dir_fd == -1:
+ raise OSError(errno, strerror(errno))
if -1 == chdir(path):
raise OSError(errno, strerror(errno))
+ else:
+ orig_dir_fd = -1
+
try:
the_dir = opendir(".")
if NULL == the_dir:
@@ -299,7 +316,7 @@
# beforehand so that eof can be distinguished from errors. See
# <https://bugs.launchpad.net/bzr/+bug/279381>
while True:
- errno = 0;
+ errno = 0
entry = readdir(the_dir)
if entry == NULL and (errno == EAGAIN or errno == EINTR):
# try again
@@ -340,10 +357,14 @@
if -1 == closedir(the_dir):
raise OSError(errno, strerror(errno))
finally:
- if -1 == chdir(cwd):
- free(cwd)
- raise OSError(errno, strerror(errno))
- free(cwd)
+ if -1 != orig_dir_fd:
+ failed = False
+ if -1 == fchdir(orig_dir_fd):
+ # try to close the original directory anyhow
+ failed = True
+ if -1 == close(orig_dir_fd) or failed:
+ raise OSError(errno, strerror(errno))
+
return result
--
bazaar-commits mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/bazaar-commits