[merge][#297831] use open/fchdir to save and restore cwd
Martin Pool
mbp at canonical.com
Fri Nov 21 04:09:10 GMT 2008
On Fri, Nov 21, 2008 at 2:23 AM, John Arbash Meinel
<john at arbash-meinel.com> wrote:
> + while entry != NULL:
> + # Unlike most libc functions, readdir needs errno set to 0
> + # beforehand so that eof can be distinguished from
> errors. See
> + # <https://bugs.launchpad.net/bzr/+bug/279381>
> + while True:
> + errno = 0;
> + entry = readdir(the_dir)
> +
>
> ^- We don't need the semicolon at the end of "errno = 0" (I realize you
> probably didn't put it there.)
Fixed.
> + if -1 != orig_dir_fd:
> + if -1 == fchdir(orig_dir_fd):
> + raise OSError(errno, strerror(errno))
> + if -1 == close(orig_dir_fd):
> + raise OSError(errno, strerror(errno))
> +
>
> ^- Do we want to raise before we close the orig_dir_fd?
Yes.
> BB:approve
>
> (I have confirmed that it works on cygwin at least.)
>
> I'm a tiny bit concerned about the implications on cygwin, in that we
> are holding open a file handle, but I'm not very concerned.
Because of a limited number of file handles, or ...?
I would not be surprised if fchdir can't be done locally and needs to
be emulated in some way in cygwin. Can we use the _walkdirs_win32
from inside cygwin?
Anyhow, I've sent it to pqm.
--
Martin <http://launchpad.net/~mbp/>
More information about the bazaar
mailing list