@@ -22,7 +22,7 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
22
22
pub mod module {
23
23
use crate :: {
24
24
builtins:: { PyDictRef , PyInt , PyListRef , PyStrRef , PyTupleRef , PyTypeRef } ,
25
- convert:: { IntoPyException , ToPyObject , TryFromObject } ,
25
+ convert:: { IntoPyException , ToPyException , ToPyObject , TryFromObject } ,
26
26
function:: { Either , KwArgs , OptionalArg } ,
27
27
ospath:: { IOErrorBuilder , OsPath , OsPathOrFd } ,
28
28
stdlib:: os:: {
@@ -279,7 +279,7 @@ pub mod module {
279
279
)
280
280
} ) ?;
281
281
282
- let metadata = fs:: metadata ( path. path . clone ( ) ) ;
282
+ let metadata = fs:: metadata ( & path. path ) ;
283
283
284
284
// if it's only checking for F_OK
285
285
if flags == AccessFlags :: F_OK {
@@ -1982,20 +1982,27 @@ pub mod module {
1982
1982
1983
1983
Errno :: clear ( ) ;
1984
1984
debug_assert_eq ! ( errno:: errno( ) , 0 ) ;
1985
- let raw = match path {
1985
+ let raw = match & path {
1986
1986
OsPathOrFd :: Path ( path) => {
1987
- let path = CString :: new ( path. into_bytes ( ) )
1988
- . map_err ( |_| vm. new_value_error ( "embedded null character" . to_owned ( ) ) ) ?;
1987
+ let path = path. clone ( ) . into_cstring ( vm) ?;
1989
1988
unsafe { libc:: pathconf ( path. as_ptr ( ) , name) }
1990
1989
}
1991
- OsPathOrFd :: Fd ( fd) => unsafe { libc:: fpathconf ( fd, name) } ,
1990
+ OsPathOrFd :: Fd ( fd) => unsafe { libc:: fpathconf ( * fd, name) } ,
1992
1991
} ;
1993
1992
1994
1993
if raw == -1 {
1995
1994
if errno:: errno ( ) == 0 {
1996
1995
Ok ( None )
1997
1996
} else {
1998
- Err ( io:: Error :: from ( Errno :: last ( ) ) . into_pyexception ( vm) )
1997
+ let exc = io:: Error :: from ( Errno :: last ( ) ) . to_pyexception ( vm) ;
1998
+ if let OsPathOrFd :: Path ( path) = & path {
1999
+ exc. as_object ( ) . set_attr (
2000
+ "filename" ,
2001
+ vm. ctx . new_str ( path. as_path ( ) . to_string_lossy ( ) ) ,
2002
+ vm,
2003
+ ) ?;
2004
+ }
2005
+ Err ( exc)
1999
2006
}
2000
2007
} else {
2001
2008
Ok ( Some ( raw) )
0 commit comments