Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r88831:093346994810
Date: 2016-12-02 17:54 +0100
http://bitbucket.org/pypy/pypy/changeset/093346994810/
Log: os.chdir(fd)
diff --git a/pypy/module/posix/interp_posix.py
b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -700,12 +700,16 @@
"""Return the current working directory as a string."""
return space.fsdecode(getcwdb(space))
-def chdir(space, w_path):
+@unwrap_spec(path=path_or_fd(allow_fd=rposix.HAVE_FCHDIR))
+def chdir(space, path):
"""Change the current working directory to the specified path."""
try:
- dispatch_filename(rposix.chdir)(space, w_path)
+ if rposix.HAVE_FCHDIR and path.as_fd != -1:
+ os.fchdir(path.as_fd)
+ else:
+ call_rposix(rposix.chdir, path)
except OSError as e:
- raise wrap_oserror2(space, e, w_path)
+ raise wrap_oserror2(space, e, path.w_path)
@unwrap_spec(mode=c_int, dir_fd=DirFD(rposix.HAVE_MKDIRAT))
def mkdir(space, w_path, mode=0o777, __kwonly__=None, dir_fd=DEFAULT_DIR_FD):
diff --git a/pypy/module/posix/test/test_posix2.py
b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -818,19 +818,20 @@
def test_fchdir(self):
os = self.posix
localdir = os.getcwd()
- try:
- os.mkdir(self.path2 + 'dir')
- fd = os.open(self.path2 + 'dir', os.O_RDONLY)
+ os.mkdir(self.path2 + 'fchdir')
+ for func in [os.fchdir, os.chdir]:
try:
- os.fchdir(fd)
- mypath = os.getcwd()
+ fd = os.open(self.path2 + 'fchdir', os.O_RDONLY)
+ try:
+ func(fd)
+ mypath = os.getcwd()
+ finally:
+ os.close(fd)
+ assert mypath.endswith('test_posix2-fchdir')
+ raises(OSError, func, fd)
finally:
- os.close(fd)
- assert mypath.endswith('test_posix2-dir')
- raises(OSError, os.fchdir, fd)
- raises(ValueError, os.fchdir, -1)
- finally:
- os.chdir(localdir)
+ os.chdir(localdir)
+ raises(ValueError, os.fchdir, -1)
def test_largefile(self):
os = self.posix
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit