Skip to content

Commit 640fc64

Browse files
committed
style: format imports and chain method calls in safe_traversal tests
1 parent 629dc36 commit 640fc64

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

src/uucore/src/lib/features/safe_traversal.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -392,21 +392,23 @@ impl DirFd {
392392
///
393393
/// Uses rustix safe wrappers to avoid raw `unsafe` FFI calls.
394394
#[cfg(target_os = "linux")]
395-
fn chmod_at_via_opath(&self, name: &CStr, mode: u32) -> io::Result<()> {
395+
fn chmod_at_via_opath(&self, name: &std::ffi::CStr, mode: u32) -> io::Result<()> {
396396
use rustix::fs::{Mode, OFlags, chmod, openat};
397397

398398
let fd = openat(
399399
&self.fd,
400400
name,
401401
OFlags::PATH | OFlags::NOFOLLOW | OFlags::CLOEXEC,
402402
Mode::empty(),
403-
)?;
403+
)
404+
.map_err(|e| io::Error::from_raw_os_error(e.raw_os_error().unwrap_or(libc::EIO)))?;
404405

405406
let proc_path = format!("/proc/self/fd/{}\0", fd.as_raw_fd());
406-
let proc_cstr = CStr::from_bytes_with_nul(proc_path.as_bytes())
407+
let proc_cstr = std::ffi::CStr::from_bytes_with_nul(proc_path.as_bytes())
407408
.map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "invalid proc path"))?;
408409

409410
chmod(proc_cstr, Mode::from_bits_truncate(mode as u32))
411+
.map_err(|e| io::Error::from_raw_os_error(e.raw_os_error().unwrap_or(libc::EIO)))
410412
}
411413

412414
/// Change mode of this directory
@@ -899,8 +901,8 @@ impl std::os::unix::fs::MetadataExt for Metadata {
899901
mod tests {
900902
use super::*;
901903
use std::fs;
902-
use std::os::unix::fs::symlink;
903904
use std::os::unix::fs::MetadataExt;
905+
use std::os::unix::fs::symlink;
904906
use std::os::unix::io::IntoRawFd;
905907
use tempfile::TempDir;
906908

@@ -1337,9 +1339,7 @@ mod tests {
13371339
// Create a sentinel file outside the traversal directory
13381340
let sentinel = temp_dir.path().join("sentinel");
13391341
fs::write(&sentinel, "victim").unwrap();
1340-
let sentinel_mode = fs::symlink_metadata(&sentinel)
1341-
.unwrap()
1342-
.mode();
1342+
let sentinel_mode = fs::symlink_metadata(&sentinel).unwrap().mode();
13431343

13441344
// Create a subdirectory with a symlink pointing to the sentinel
13451345
let subdir = temp_dir.path().join("subdir");
@@ -1356,9 +1356,7 @@ mod tests {
13561356
// which is acceptable — the important thing is the target is NOT modified.
13571357
if let Ok(()) = result {
13581358
// fchmodat2 succeeded: verify sentinel mode is unchanged
1359-
let new_sentinel_mode = fs::symlink_metadata(&sentinel)
1360-
.unwrap()
1361-
.mode();
1359+
let new_sentinel_mode = fs::symlink_metadata(&sentinel).unwrap().mode();
13621360
assert_eq!(
13631361
new_sentinel_mode, sentinel_mode,
13641362
"sentinel mode should not change when chmod'ing symlink with NoFollow"

0 commit comments

Comments
 (0)