From f9c76edd23b7284f96ac0ae39c22574fe5ffa1b9 Mon Sep 17 00:00:00 2001 From: Ruoqing He Date: Fri, 23 May 2025 11:44:51 +0000 Subject: [PATCH] agent: Fix clippy `manual_inspect` Manually fix `manual_inspect` clippy warning reported by rust 1.85.1. ```console warning: using `map_err` over `inspect_err` --> rustjail/src/mount.rs:881:6 | 881 | .map_err(|e| { | ^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_inspect help: try | 881 ~ .inspect_err(|&e| { 882 ~ log_child!(cfd_log, "mount error: {:?}", e); | ``` Signed-off-by: Ruoqing He --- src/agent/rustjail/src/container.rs | 21 +++++++-------------- src/agent/rustjail/src/mount.rs | 27 ++++++++------------------- src/agent/src/storage/mod.rs | 5 ++--- 3 files changed, 17 insertions(+), 36 deletions(-) diff --git a/src/agent/rustjail/src/container.rs b/src/agent/rustjail/src/container.rs index 9f9ecaa0af..327232ada5 100644 --- a/src/agent/rustjail/src/container.rs +++ b/src/agent/rustjail/src/container.rs @@ -461,15 +461,14 @@ fn do_init_child(cwfd: RawFd) -> Result<()> { } } else { let fd = fcntl::open(ns.path().as_ref().unwrap(), OFlag::O_CLOEXEC, Mode::empty()) - .map_err(|e| { + .inspect_err(|e| { log_child!( cfd_log, "cannot open type: {} path: {}", &ns.typ().to_string(), ns.path().as_ref().unwrap().display() ); - log_child!(cfd_log, "error is : {:?}", e); - e + log_child!(cfd_log, "error is : {:?}", e) })?; if *s != CloneFlags::CLONE_NEWPID { @@ -685,14 +684,12 @@ fn do_init_child(cwfd: RawFd) -> Result<()> { .map(|gid| Gid::from_raw(*gid)) .collect(); - unistd::setgroups(&gids).map_err(|e| { + unistd::setgroups(&gids).inspect_err(|e| { let _ = write_sync( cwfd, SYNC_FAILED, format!("setgroups failed: {:?}", e).as_str(), ); - - e })?; } @@ -1449,16 +1446,14 @@ fn get_pid_namespace(logger: &Logger, linux: &Linux) -> Result { OFlag::O_RDONLY, Mode::empty(), ) - .map_err(|e| { + .inspect_err(|e| { error!( logger, "cannot open type: {} path: {}", &ns.typ().to_string(), ns_path.display() ); - error!(logger, "error is : {:?}", e); - - e + error!(logger, "error is : {:?}", e) })?, }; @@ -1639,10 +1634,8 @@ fn write_mappings(logger: &Logger, path: &str, maps: &[LinuxIdMapping]) -> Resul if !data.is_empty() { let fd = fcntl::open(path, OFlag::O_WRONLY, Mode::empty())?; defer!(unistd::close(fd).unwrap()); - unistd::write(fd, data.as_bytes()).map_err(|e| { - info!(logger, "cannot write mapping"); - e - })?; + unistd::write(fd, data.as_bytes()) + .inspect_err(|_| info!(logger, "cannot write mapping"))?; } Ok(()) } diff --git a/src/agent/rustjail/src/mount.rs b/src/agent/rustjail/src/mount.rs index 9363c25f4d..f858bd05a4 100644 --- a/src/agent/rustjail/src/mount.rs +++ b/src/agent/rustjail/src/mount.rs @@ -481,16 +481,14 @@ fn mount_cgroups( if key != base { let src = format!("{}/{}", &mount_dest, key); - unix::fs::symlink(destination.as_str(), &src[1..]).map_err(|e| { + unix::fs::symlink(destination.as_str(), &src[1..]).inspect_err(|e| { log_child!( cfd_log, "symlink: {} {} err: {}", key, destination.as_str(), e.to_string() - ); - - e + ) })?; } } @@ -793,14 +791,13 @@ fn mount_from( Path::new(&dest).parent().unwrap() }; - fs::create_dir_all(dir).map_err(|e| { + fs::create_dir_all(dir).inspect_err(|e| { log_child!( cfd_log, "create dir {}: {}", dir.to_str().unwrap(), e.to_string() - ); - e + ) })?; // make sure file exists so we can bind over it @@ -830,10 +827,8 @@ fn mount_from( } }; - let _ = stat::stat(dest.as_str()).map_err(|e| { - log_child!(cfd_log, "dest stat error. {}: {:?}", dest.as_str(), e); - e - })?; + let _ = stat::stat(dest.as_str()) + .inspect_err(|e| log_child!(cfd_log, "dest stat error. {}: {:?}", dest.as_str(), e))?; // Set the SELinux context for the mounts let mut use_xattr = false; @@ -878,10 +873,7 @@ fn mount_from( flags, Some(d.as_str()), ) - .map_err(|e| { - log_child!(cfd_log, "mount error: {:?}", e); - e - })?; + .inspect_err(|e| log_child!(cfd_log, "mount error: {:?}", e))?; if !label.is_empty() && selinux::is_enabled()? && use_xattr { xattr::set(dest.as_str(), "security.selinux", label.as_bytes())?; @@ -904,10 +896,7 @@ fn mount_from( flags | MsFlags::MS_REMOUNT, None::<&str>, ) - .map_err(|e| { - log_child!(cfd_log, "remout {}: {:?}", dest.as_str(), e); - e - })?; + .inspect_err(|e| log_child!(cfd_log, "remout {}: {:?}", dest.as_str(), e))?; } Ok(()) } diff --git a/src/agent/src/storage/mod.rs b/src/agent/src/storage/mod.rs index c1f87b9a42..3b18f345e0 100644 --- a/src/agent/src/storage/mod.rs +++ b/src/agent/src/storage/mod.rs @@ -321,12 +321,11 @@ pub fn set_ownership(logger: &Logger, storage: &Storage) -> Result<()> { let fs_group = storage.fs_group(); let read_only = storage.options.contains(&String::from("ro")); let mount_path = Path::new(&storage.mount_point); - let metadata = mount_path.metadata().map_err(|err| { + let metadata = mount_path.metadata().inspect_err(|err| { error!(logger, "failed to obtain metadata for mount path"; "mount-path" => mount_path.to_str(), "error" => err.to_string(), - ); - err + ) })?; if fs_group.group_change_policy == FSGroupChangePolicy::OnRootMismatch.into()