@@ -120,8 +120,7 @@ pub fn os_open(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
120
120
} ;
121
121
let fname = & make_path ( vm, name, & dir_fd) . value ;
122
122
123
- let mut options = OpenOptions :: new ( ) ;
124
- let options = _set_file_model ( & mut options, flags) ;
123
+ let options = _set_file_model ( & flags) ;
125
124
let handle = options
126
125
. open ( & fname)
127
126
. map_err ( |err| convert_io_error ( vm, err) ) ?;
@@ -130,15 +129,25 @@ pub fn os_open(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
130
129
}
131
130
132
131
#[ cfg( unix) ]
133
- fn _set_file_model < ' a > ( options : & ' a mut OpenOptions , flags : & PyObjectRef ) -> & ' a mut OpenOptions {
132
+ fn _set_file_model ( flags : & PyObjectRef ) -> OpenOptions {
134
133
let flags = objint:: get_value ( flags) . to_i32 ( ) . unwrap ( ) ;
135
- options. custom_flags ( flags)
134
+ let mut options = OpenOptions :: new ( ) ;
135
+ options. read ( flags & libc:: O_RDONLY != 0 ) ;
136
+ options. write ( flags & libc:: O_WRONLY != 0 ) ;
137
+ options. append ( flags & libc:: O_APPEND != 0 ) ;
138
+ options. custom_flags ( flags) ;
139
+ options
136
140
}
137
141
138
142
#[ cfg( windows) ]
139
- fn _set_file_model < ' a > ( options : & ' a mut OpenOptions , flags : & PyObjectRef ) -> & ' a mut OpenOptions {
143
+ fn _set_file_model ( flags : & PyObjectRef ) -> OpenOptions {
140
144
let flags = objint:: get_value ( flags) . to_u32 ( ) . unwrap ( ) ;
141
- options. custom_flags ( flags)
145
+ let mut options = OpenOptions :: new ( ) ;
146
+ options. read ( ( flags as i32 ) & libc:: O_RDONLY != 0 ) ;
147
+ options. write ( ( flags as i32 ) & libc:: O_WRONLY != 0 ) ;
148
+ options. append ( ( flags as i32 ) & libc:: O_APPEND != 0 ) ;
149
+ options. custom_flags ( flags) ;
150
+ options
142
151
}
143
152
144
153
#[ cfg( all( not( unix) , not( windows) ) ) ]
@@ -1237,7 +1246,6 @@ fn extend_module_platform_specific(vm: &VirtualMachine, module: PyObjectRef) ->
1237
1246
"setuid" => ctx. new_rustfunc( os_setuid) ,
1238
1247
"access" => ctx. new_rustfunc( os_access) ,
1239
1248
"O_DSYNC" => ctx. new_int( libc:: O_DSYNC ) ,
1240
- "O_RSYNC" => ctx. new_int( 1052672 ) ,
1241
1249
"O_NDELAY" => ctx. new_int( libc:: O_NDELAY ) ,
1242
1250
"O_NOCTTY" => ctx. new_int( libc:: O_NOCTTY ) ,
1243
1251
"O_CLOEXEC" => ctx. new_int( libc:: O_CLOEXEC ) ,
0 commit comments