From 4dd9bd7aba311b626dd6b784ab216c63bd9163eb Mon Sep 17 00:00:00 2001 From: bin liu Date: Fri, 16 Oct 2020 16:15:15 +0800 Subject: [PATCH] agent: clear clippy `len_zero` warnings Use `.is_empty()` instead of `.len() == 0`, `.len() >0` and `.len() != 0` Signed-off-by: bin liu --- src/agent/rustjail/src/cgroups/fs/mod.rs | 8 ++++---- src/agent/rustjail/src/container.rs | 2 +- src/agent/rustjail/src/validator.rs | 6 +++--- src/agent/src/mount.rs | 14 +++++++------- src/agent/src/network.rs | 2 +- src/agent/src/rpc.rs | 6 +++--- src/agent/src/sandbox.rs | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/agent/rustjail/src/cgroups/fs/mod.rs b/src/agent/rustjail/src/cgroups/fs/mod.rs index 880a7ece1d..160a991e7b 100644 --- a/src/agent/rustjail/src/cgroups/fs/mod.rs +++ b/src/agent/rustjail/src/cgroups/fs/mod.rs @@ -126,7 +126,7 @@ impl CgroupManager for Manager { } // set hugepages resources - if r.hugepage_limits.len() > 0 { + if !r.hugepage_limits.is_empty() { set_hugepages_resources(&cg, &r.hugepage_limits, res)?; } @@ -789,7 +789,7 @@ https://github.com/opencontainers/runc/blob/a5847db387ae28c0ca4ebe4beee1a76900c8 fn get_blkio_stat_blkiodata(blkiodata: &[BlkIoData]) -> RepeatedField { let mut m = RepeatedField::new(); - if blkiodata.len() == 0 { + if blkiodata.is_empty() { return m; } @@ -812,7 +812,7 @@ fn get_blkio_stat_blkiodata(blkiodata: &[BlkIoData]) -> RepeatedField RepeatedField { let mut m = RepeatedField::new(); - if services.len() == 0 { + if services.is_empty() { return m; } @@ -874,7 +874,7 @@ fn get_blkio_stats(cg: &cgroups::Cgroup) -> SingularPtrField { let mut m = BlkioStats::new(); let io_serviced_recursive = blkio.io_serviced_recursive; - if io_serviced_recursive.len() == 0 { + if io_serviced_recursive.is_empty() { // fall back to generic stats // blkio.throttle.io_service_bytes, // maybe io_service_bytes_recursive? diff --git a/src/agent/rustjail/src/container.rs b/src/agent/rustjail/src/container.rs index db4a16bc28..1cc207a91f 100644 --- a/src/agent/rustjail/src/container.rs +++ b/src/agent/rustjail/src/container.rs @@ -547,7 +547,7 @@ fn do_init_child(cwfd: RawFd) -> Result<()> { setid(uid, gid)?; - if guser.additional_gids.len() > 0 { + if !guser.additional_gids.is_empty() { setgroups(guser.additional_gids.as_slice()).map_err(|e| { let _ = write_sync( cwfd, diff --git a/src/agent/rustjail/src/validator.rs b/src/agent/rustjail/src/validator.rs index abe0124b96..1da4da2e19 100644 --- a/src/agent/rustjail/src/validator.rs +++ b/src/agent/rustjail/src/validator.rs @@ -88,7 +88,7 @@ fn hostname(oci: &Spec) -> Result<()> { fn security(oci: &Spec) -> Result<()> { let linux = oci.linux.as_ref().unwrap(); - if linux.masked_paths.len() == 0 && linux.readonly_paths.len() == 0 { + if linux.masked_paths.is_empty() && linux.readonly_paths.is_empty() { return Ok(()); } @@ -124,7 +124,7 @@ fn usernamespace(oci: &Spec) -> Result<()> { idmapping(&linux.gid_mappings)?; } else { // no user namespace but idmap - if linux.uid_mappings.len() != 0 || linux.gid_mappings.len() != 0 { + if !linux.uid_mappings.is_empty() || !linux.gid_mappings.is_empty() { return Err(anyhow!(nix::Error::from_errno(Errno::EINVAL))); } } @@ -222,7 +222,7 @@ fn rootless_euid_mapping(oci: &Spec) -> Result<()> { return Err(anyhow!(nix::Error::from_errno(Errno::EINVAL))); } - if linux.uid_mappings.len() == 0 || linux.gid_mappings.len() == 0 { + if linux.uid_mappings.is_empty() || linux.gid_mappings.is_empty() { // rootless containers requires at least one UID/GID mapping return Err(anyhow!(nix::Error::from_errno(Errno::EINVAL))); } diff --git a/src/agent/src/mount.rs b/src/agent/src/mount.rs index 8b98e9046c..66d1673114 100644 --- a/src/agent/src/mount.rs +++ b/src/agent/src/mount.rs @@ -190,11 +190,11 @@ impl<'a> BareMount<'a> { let cstr_dest: CString; let cstr_fs_type: CString; - if self.source.len() == 0 { + if self.source.is_empty() { return Err(anyhow!("need mount source")); } - if self.destination.len() == 0 { + if self.destination.is_empty() { return Err(anyhow!("need mount destination")); } @@ -204,14 +204,14 @@ impl<'a> BareMount<'a> { cstr_dest = CString::new(self.destination)?; dest = cstr_dest.as_ptr(); - if self.fs_type.len() == 0 { + if self.fs_type.is_empty() { return Err(anyhow!("need mount FS type")); } cstr_fs_type = CString::new(self.fs_type)?; fs_type = cstr_fs_type.as_ptr(); - if self.options.len() > 0 { + if !self.options.is_empty() { cstr_options = CString::new(self.options)?; options = cstr_options.as_ptr() as *const c_void; } @@ -407,14 +407,14 @@ fn parse_mount_flags_and_options(options_vec: Vec<&str>) -> (MsFlags, String) { let mut options: String = "".to_string(); for opt in options_vec { - if opt.len() != 0 { + if !opt.is_empty() { match FLAGS.get(opt) { Some(x) => { let (_, f) = *x; flags |= f; } None => { - if options.len() > 0 { + if !options.is_empty() { options.push_str(format!(",{}", opt).as_str()); } else { options.push_str(opt.to_string().as_str()); @@ -455,7 +455,7 @@ pub fn add_storages( // Todo need to rollback the mounted storage if err met. let mount_point = handler(&logger, &storage, sandbox.clone())?; - if mount_point.len() > 0 { + if !mount_point.is_empty() { mount_list.push(mount_point); } } diff --git a/src/agent/src/network.rs b/src/agent/src/network.rs index 829149cdfd..4d1f3e25bd 100644 --- a/src/agent/src/network.rs +++ b/src/agent/src/network.rs @@ -48,7 +48,7 @@ pub fn setup_guest_dns(logger: Logger, dns_list: Vec) -> Result<()> { fn do_setup_guest_dns(logger: Logger, dns_list: Vec, src: &str, dst: &str) -> Result<()> { let logger = logger.new(o!( "subsystem" => "network")); - if dns_list.len() == 0 { + if dns_list.is_empty() { info!( logger, "Did not set sandbox DNS as DNS not received as part of request." diff --git a/src/agent/src/rpc.rs b/src/agent/src/rpc.rs index 60d1af02d0..565e0ba228 100644 --- a/src/agent/src/rpc.rs +++ b/src/agent/src/rpc.rs @@ -609,7 +609,7 @@ impl protocols::agent_ttrpc::AgentService for agentService { } // format "table" - if args.len() == 0 { + if args.is_empty() { // default argument args = vec!["-ef".to_string()]; } @@ -1007,7 +1007,7 @@ impl protocols::agent_ttrpc::AgentService for agentService { }); } - if req.sandbox_id.len() > 0 { + if !req.sandbox_id.is_empty() { s.id = req.sandbox_id.clone(); } @@ -1248,7 +1248,7 @@ fn get_memory_info(block_size: bool, hotplug: bool) -> Result<(u64, bool)> { if block_size { match fs::read_to_string(SYSFS_MEMORY_BLOCK_SIZE_PATH) { Ok(v) => { - if v.len() == 0 { + if v.is_empty() { info!(sl!(), "string in empty???"); return Err(anyhow!("Invalid block size")); } diff --git a/src/agent/src/sandbox.rs b/src/agent/src/sandbox.rs index 9f35af4106..83fb0123f3 100644 --- a/src/agent/src/sandbox.rs +++ b/src/agent/src/sandbox.rs @@ -184,7 +184,7 @@ impl Sandbox { // This means a separate pause process has not been created. We treat the // first container created as the infra container in that case // and use its pid namespace in case pid namespace needs to be shared. - if self.sandbox_pidns.is_none() && self.containers.len() == 0 { + if self.sandbox_pidns.is_none() && self.containers.is_empty() { let init_pid = c.init_process_pid; if init_pid == -1 { return Err(anyhow!(