Skip to content

Commit

Permalink
avoid double negation
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdrz committed Dec 30, 2019
1 parent ce4e1f9 commit a40a99d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/shims/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use shims::time::system_time_to_duration;
#[derive(Debug)]
pub struct FileHandle {
file: File,
read_only: bool,
writable: bool,
}

pub struct FileHandler {
Expand Down Expand Up @@ -57,13 +57,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
if (o_rdonly | o_wronly | o_rdwr) & !0b11 != 0 {
throw_unsup_format!("Access mode flags on this platform are unsupported");
}
let mut read_only = false;
let mut writable = true;

// Now we check the access mode
let access_mode = flag & 0b11;

if access_mode == o_rdonly {
read_only = true;
writable = false;
options.read(true);
} else if access_mode == o_wronly {
options.write(true);
Expand Down Expand Up @@ -109,7 +109,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let fd = options.open(&path).map(|file| {
let mut fh = &mut this.machine.file_handler;
fh.low += 1;
fh.handles.insert(fh.low, FileHandle { file, read_only }).unwrap_none();
fh.handles.insert(fh.low, FileHandle { file, writable }).unwrap_none();
fh.low
});

Expand Down Expand Up @@ -153,7 +153,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx

if let Some(handle) = this.machine.file_handler.handles.remove(&fd) {
// We sync the file if it was opened in a mode different than read-only.
if !handle.read_only {
if handle.writable {
// `File::sync_all` does the checks that are done when closing a file. We do this to
// to handle possible errors correctly.
let result = this.try_unwrap_io_result(handle.file.sync_all().map(|_| 0i32));
Expand All @@ -164,7 +164,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
} else {
// We drop the file, this closes it but ignores any errors produced when closing
// it. This is done because `File::sync_call` cannot be done over files like
// `/dev/urandom`. Check
// `/dev/urandom` which are read-only. Check
// https://github.com/rust-lang/miri/issues/999#issuecomment-568920439 for a deeper
// discussion.
drop(handle);
Expand Down

0 comments on commit a40a99d

Please sign in to comment.