Skip to content

Commit fc63eef

Browse files
committed
fix windows error
1 parent fd18784 commit fc63eef

File tree

1 file changed

+15
-4
lines changed
  • crates/vm/src/stdlib

1 file changed

+15
-4
lines changed

crates/vm/src/stdlib/nt.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub(crate) mod module {
1717
builtins::{PyBaseExceptionRef, PyDictRef, PyListRef, PyStrRef, PyTupleRef},
1818
common::{crt_fd, suppress_iph, windows::ToWideString},
1919
convert::ToPyException,
20+
exceptions::OSErrorBuilder,
2021
function::{Either, OptionalArg},
2122
ospath::{OsPath, OsPathOrFd},
2223
stdlib::os::{_os, DirFd, SupportFunc, TargetIsDirectory},
@@ -193,10 +194,12 @@ pub(crate) mod module {
193194
};
194195

195196
// Use symlink_metadata to avoid following dangling symlinks
196-
let meta = fs::symlink_metadata(&actual_path).map_err(|err| err.to_pyexception(vm))?;
197+
let meta = fs::symlink_metadata(&actual_path)
198+
.map_err(|err| OSErrorBuilder::with_filename(&err, path.clone(), vm))?;
197199
let mut permissions = meta.permissions();
198200
permissions.set_readonly(mode & S_IWRITE == 0);
199-
fs::set_permissions(&*actual_path, permissions).map_err(|err| err.to_pyexception(vm))
201+
fs::set_permissions(&*actual_path, permissions)
202+
.map_err(|err| OSErrorBuilder::with_filename(&err, path, vm))
200203
}
201204

202205
/// Get the real file name (with correct case) without accessing the file.
@@ -1602,7 +1605,11 @@ pub(crate) mod module {
16021605
};
16031606

16041607
if handle == INVALID_HANDLE_VALUE {
1605-
return Err(io::Error::last_os_error().to_pyexception(vm));
1608+
return Err(OSErrorBuilder::with_filename(
1609+
&io::Error::last_os_error(),
1610+
path.clone(),
1611+
vm,
1612+
));
16061613
}
16071614

16081615
// Buffer for reparse data - MAXIMUM_REPARSE_DATA_BUFFER_SIZE is 16384
@@ -1626,7 +1633,11 @@ pub(crate) mod module {
16261633
unsafe { CloseHandle(handle) };
16271634

16281635
if result == 0 {
1629-
return Err(io::Error::last_os_error().to_pyexception(vm));
1636+
return Err(OSErrorBuilder::with_filename(
1637+
&io::Error::last_os_error(),
1638+
path.clone(),
1639+
vm,
1640+
));
16301641
}
16311642

16321643
// Parse the reparse data buffer

0 commit comments

Comments
 (0)