Skip to content

Commit

Permalink
fix clippy warning
Browse files Browse the repository at this point in the history
  • Loading branch information
el-ev committed Feb 27, 2025
1 parent 989c19b commit 34a7131
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/shims/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use std::borrow::Cow;
use std::fs::{
DirBuilder, File, FileType, Metadata, OpenOptions, Permissions, ReadDir, read_dir, remove_dir,
remove_file, rename,
DirBuilder, File, FileType, Metadata, OpenOptions, ReadDir, read_dir, remove_dir, remove_file,
rename,
};
use std::io::{self, ErrorKind, IsTerminal, Read, Seek, SeekFrom, Write};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -1668,9 +1668,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn chmod(&mut self, path_op: &OpTy<'tcx>, perm_op: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> {
let this = self.eval_context_mut();

let pathname = this.read_path_from_c_str(this.read_pointer(path_op)?)?;
let perm = this.read_scalar(perm_op)?.to_uint(this.libc_ty_layout("mode_t").size)?;

// Reject if isolation is enabled.
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
this.reject_in_isolation("`chmod`", reject_with)?;
Expand All @@ -1680,8 +1677,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Permissions::from_mode is Unix-specific.
#[cfg(unix)]
{
use std::fs::Permissions;
use std::os::unix::fs::PermissionsExt;

let pathname = this.read_path_from_c_str(this.read_pointer(path_op)?)?;
let perm = this.read_scalar(perm_op)?.to_uint(this.libc_ty_layout("mode_t").size)?;

let result = std::fs::set_permissions(
pathname,
Permissions::from_mode(perm.try_into().unwrap()),
Expand All @@ -1692,27 +1693,30 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
}
#[cfg(not(unix))]
{
let (_, _) = (path_op, perm_op);
throw_unsup_format!("`chmod` is not supported on this platform")
}
}

fn fchmod(&mut self, fd_op: &OpTy<'tcx>, perm_op: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> {
let this = self.eval_context_mut();

let fd = this.read_scalar(fd_op)?.to_i32()?;
let perm = this.read_scalar(perm_op)?.to_uint(this.libc_ty_layout("mode_t").size)?;

// Reject if isolation is enabled.
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
this.reject_in_isolation("`fchmod`", reject_with)?;
// Set error code as "EBADF" (bad fd)
return this.set_last_error_and_return_i32(LibcError("EBADF"));
}

// `Permissions::from_mode` is Unix-specific.
#[cfg(unix)]
{
use std::fs::Permissions;
use std::os::unix::fs::PermissionsExt;

let fd = this.read_scalar(fd_op)?.to_i32()?;
let perm = this.read_scalar(perm_op)?.to_uint(this.libc_ty_layout("mode_t").size)?;

let Some(fd) = this.machine.fds.get(fd) else {
return this.set_last_error_and_return_i32(LibcError("EBADF"));
};
Expand All @@ -1729,6 +1733,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
}
#[cfg(not(unix))]
{
let (_, _) = (fd_op, perm_op);
throw_unsup_format!("`fchmod` is not supported on this platform")
}
}
Expand Down

0 comments on commit 34a7131

Please sign in to comment.