mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 10:44:36 +08:00
Set errno on os.listdir
This commit is contained in:
1 parent
92d0f05242
commit
83386fda25
2 files changed
+8
-13
No files matched your search
@@ -1201,7 +1201,6 @@ class ExceptionTests(unittest.TestCase):
|
||||
self.fail("RecursionError not raised")
|
||||
self.assertEqual(wr(), None)
|
||||
|
||||
@unittest.skip("TODO: RUSTPYTHON")
|
||||
def test_errno_ENOTDIR(self):
|
||||
# Issue #12802: "not a directory" errors are ENOTDIR even on Windows
|
||||
with self.assertRaises(OSError) as cm:
|
||||
|
||||
+8
-12
@@ -413,18 +413,14 @@ fn os_rmdir(path: PyStringRef, dir_fd: DirFd, vm: &VirtualMachine) -> PyResult<(
|
||||
}
|
||||
|
||||
fn os_listdir(path: PyStringRef, vm: &VirtualMachine) -> PyResult {
|
||||
match fs::read_dir(path.as_str()) {
|
||||
Ok(iter) => {
|
||||
let res: PyResult<Vec<PyObjectRef>> = iter
|
||||
.map(|entry| match entry {
|
||||
Ok(path) => Ok(vm.ctx.new_str(path.file_name().into_string().unwrap())),
|
||||
Err(s) => Err(convert_io_error(vm, s)),
|
||||
})
|
||||
.collect();
|
||||
Ok(vm.ctx.new_list(res?))
|
||||
}
|
||||
Err(s) => Err(vm.new_os_error(s.to_string())),
|
||||
}
|
||||
let res: PyResult<Vec<PyObjectRef>> = fs::read_dir(path.as_str())
|
||||
.map_err(|err| convert_io_error(vm, err))?
|
||||
.map(|entry| match entry {
|
||||
Ok(path) => Ok(vm.ctx.new_str(path.file_name().into_string().unwrap())),
|
||||
Err(s) => Err(convert_io_error(vm, s)),
|
||||
})
|
||||
.collect();
|
||||
Ok(vm.ctx.new_list(res?))
|
||||
}
|
||||
|
||||
fn bytes_as_osstr<'a>(b: &'a [u8], vm: &VirtualMachine) -> PyResult<&'a ffi::OsStr> {
|
||||
|
||||
Reference in new issue
Block a user