Skip to content

Commit 3f229f2

Browse files
committed
fix errors
1 parent 4a322b5 commit 3f229f2

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

vm/src/stdlib/os.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ pub fn os_open(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
120120
};
121121
let fname = &make_path(vm, name, &dir_fd).value;
122122

123-
let mut options = OpenOptions::new();
124-
let options = _set_file_model(&mut options, flags);
123+
let options = _set_file_model(&flags);
125124
let handle = options
126125
.open(&fname)
127126
.map_err(|err| convert_io_error(vm, err))?;
@@ -130,15 +129,25 @@ pub fn os_open(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
130129
}
131130

132131
#[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 {
134133
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
136140
}
137141

138142
#[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 {
140144
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
142151
}
143152

144153
#[cfg(all(not(unix), not(windows)))]
@@ -1237,7 +1246,6 @@ fn extend_module_platform_specific(vm: &VirtualMachine, module: PyObjectRef) ->
12371246
"setuid" => ctx.new_rustfunc(os_setuid),
12381247
"access" => ctx.new_rustfunc(os_access),
12391248
"O_DSYNC" => ctx.new_int(libc::O_DSYNC),
1240-
"O_RSYNC" => ctx.new_int(1052672),
12411249
"O_NDELAY" => ctx.new_int(libc::O_NDELAY),
12421250
"O_NOCTTY" => ctx.new_int(libc::O_NOCTTY),
12431251
"O_CLOEXEC" => ctx.new_int(libc::O_CLOEXEC),

0 commit comments

Comments
 (0)