Skip to content

Commit d6bd3b5

Browse files
committed
vexos: fix logic regarding create and create_new
1 parent 54cef26 commit d6bd3b5

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

library/std/src/sys/fs/vexos.rs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -225,27 +225,41 @@ impl File {
225225

226226
// append
227227
(false, _, true, false, create, create_new) => unsafe {
228-
if create_new && vex_sdk::vexFileStatus(path.as_ptr()) != 0 {
229-
return Err(io::Error::new(io::ErrorKind::AlreadyExists, "File exists"));
230-
} else if !create && vex_sdk::vexFileStatus(path.as_ptr()) == 0 {
231-
return Err(io::Error::new(
232-
io::ErrorKind::NotFound,
233-
"No such file or directory",
234-
));
228+
if create_new {
229+
if vex_sdk::vexFileStatus(path.as_ptr()) != 0 {
230+
return Err(io::Error::new(
231+
io::ErrorKind::AlreadyExists,
232+
"File exists",
233+
));
234+
}
235+
} else if !create {
236+
if vex_sdk::vexFileStatus(path.as_ptr()) == 0 {
237+
return Err(io::Error::new(
238+
io::ErrorKind::NotFound,
239+
"No such file or directory",
240+
));
241+
}
235242
}
236243

237244
vex_sdk::vexFileOpenWrite(path.as_ptr())
238245
},
239246

240247
// write
241248
(false, true, false, truncate, create, create_new) => unsafe {
242-
if create_new && vex_sdk::vexFileStatus(path.as_ptr()) != 0 {
243-
return Err(io::Error::new(io::ErrorKind::AlreadyExists, "File exists"));
244-
} else if !create && vex_sdk::vexFileStatus(path.as_ptr()) == 0 {
245-
return Err(io::Error::new(
246-
io::ErrorKind::NotFound,
247-
"No such file or directory",
248-
));
249+
if create_new {
250+
if vex_sdk::vexFileStatus(path.as_ptr()) != 0 {
251+
return Err(io::Error::new(
252+
io::ErrorKind::AlreadyExists,
253+
"File exists",
254+
));
255+
}
256+
} else if !create {
257+
if vex_sdk::vexFileStatus(path.as_ptr()) == 0 {
258+
return Err(io::Error::new(
259+
io::ErrorKind::NotFound,
260+
"No such file or directory",
261+
));
262+
}
249263
}
250264

251265
if truncate {

0 commit comments

Comments
 (0)