Content-Length: 513492 | pFad | http://github.com/RustPython/RustPython/commit/679af3f990fb8dbcf3a41972315e32db6654e7aa

E1 fix bugs · RustPython/RustPython@679af3f · GitHub
Skip to content

Commit 679af3f

Browse files
committed
fix bugs
1 parent 15558e0 commit 679af3f

File tree

1 file changed

+43
-24
lines changed

1 file changed

+43
-24
lines changed

vm/src/stdlib/nt.rs

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,8 @@ pub(crate) mod module {
427427
#[pyfunction]
428428
fn listvolumes(vm: &VirtualMachine) -> PyResult<PyListRef> {
429429
let mut volumes = vec![];
430-
let find;
431430
let mut buffer = [0u16; 257];
432-
find = unsafe {
433-
FileSystem::FindFirstVolumeW(
434-
buffer.as_mut_ptr(),
435-
buffer.len() as _,
436-
)
437-
};
431+
let find = unsafe { FileSystem::FindFirstVolumeW(buffer.as_mut_ptr(), buffer.len() as _) };
438432
if find == windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE {
439433
return Err(errno_err(vm));
440434
}
@@ -447,11 +441,7 @@ pub(crate) mod module {
447441
}
448442
volumes.push(s.to_string());
449443
let ret = unsafe {
450-
FileSystem::FindNextVolumeW(
451-
find,
452-
buffer.as_mut_ptr(),
453-
buffer.len() as _,
454-
)
444+
FileSystem::FindNextVolumeW(find, buffer.as_mut_ptr(), buffer.len() as _)
455445
};
456446
if ret == 0 {
457447
err = std::io::Error::last_os_error().raw_os_error().unwrap_or(0);
@@ -463,10 +453,7 @@ pub(crate) mod module {
463453
if err != 0 && err != windows_sys::Win32::Foundation::ERROR_NO_MORE_FILES as i32 {
464454
return Err(std::io::Error::from_raw_os_error(err).to_pyexception(vm));
465455
}
466-
let volumes: Vec<_> = volumes
467-
.into_iter()
468-
.map(|v| vm.new_pyobj(v))
469-
.collect();
456+
let volumes: Vec<_> = volumes.into_iter().map(|v| vm.new_pyobj(v)).collect();
470457
Ok(vm.ctx.new_list(volumes))
471458
}
472459

@@ -481,8 +468,16 @@ pub(crate) mod module {
481468
if path.is_dir() {
482469
return Ok(false);
483470
}
484-
let metadata = fs::metadata(path).map_err(|err| err.to_pyexception(vm))?;
485-
Ok(metadata.is_file())
471+
let metadata = fs::metadata(path);
472+
match metadata {
473+
Ok(meta) => Ok(meta.is_file()),
474+
Err(err) => {
475+
if err.kind() == io::ErrorKind::NotFound {
476+
return Ok(false);
477+
}
478+
Err(err.to_pyexception(vm))
479+
}
480+
}
486481
}
487482

488483
#[pyfunction]
@@ -494,8 +489,16 @@ pub(crate) mod module {
494489
if path.exists() {
495490
return Ok(false);
496491
}
497-
let metadata = fs::metadata(path).map_err(|err| err.to_pyexception(vm))?;
498-
Ok(metadata.is_dir())
492+
let metadata = fs::metadata(path);
493+
match metadata {
494+
Ok(meta) => Ok(meta.is_dir()),
495+
Err(err) => {
496+
if err.kind() == io::ErrorKind::NotFound {
497+
return Ok(false);
498+
}
499+
Err(err.to_pyexception(vm))
500+
}
501+
}
499502
}
500503

501504
#[pyfunction]
@@ -507,8 +510,16 @@ pub(crate) mod module {
507510
if path.exists() {
508511
return Ok(false);
509512
}
510-
let metadata = fs::metadata(path).map_err(|err| err.to_pyexception(vm))?;
511-
Ok(metadata.is_file())
513+
let metadata = fs::metadata(path);
514+
match metadata {
515+
Ok(meta) => Ok(meta.is_file()),
516+
Err(err) => {
517+
if err.kind() == io::ErrorKind::NotFound {
518+
return Ok(false);
519+
}
520+
Err(err.to_pyexception(vm))
521+
}
522+
}
512523
}
513524

514525
#[pyfunction]
@@ -520,8 +531,16 @@ pub(crate) mod module {
520531
if path.exists() {
521532
return Ok(false);
522533
}
523-
let metadata = fs::symlink_metadata(path).map_err(|err| err.to_pyexception(vm))?;
524-
Ok(metadata.file_type().is_symlink())
534+
let metadata = fs::symlink_metadata(path);
535+
match metadata {
536+
Ok(meta) => Ok(meta.file_type().is_symlink()),
537+
Err(err) => {
538+
if err.kind() == io::ErrorKind::NotFound {
539+
return Ok(false);
540+
}
541+
Err(err.to_pyexception(vm))
542+
}
543+
}
525544
}
526545

527546
// End of functions that are not fully compatible with CPython

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/RustPython/RustPython/commit/679af3f990fb8dbcf3a41972315e32db6654e7aa

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy