agent: clear clippy len_zero warnings

Use `.is_empty()` instead of `.len() == 0`, `.len() >0`
and `.len() != 0`

Signed-off-by: bin liu <bin@hyper.sh>
Signed-off-by: Chelsea Mafrica <chelsea.e.mafrica@intel.com>
This commit is contained in:
bin liu 2020-10-16 16:15:15 +08:00 committed by Chelsea Mafrica
parent 165988a394
commit 02aaab2213
7 changed files with 19 additions and 19 deletions

View File

@ -135,7 +135,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)?;
}
@ -780,7 +780,7 @@ https://github.com/opencontainers/runc/blob/a5847db387ae28c0ca4ebe4beee1a76900c8
fn get_blkio_stat_blkiodata(blkiodata: &[BlkIoData]) -> RepeatedField<BlkioStatsEntry> {
let mut m = RepeatedField::new();
if blkiodata.len() == 0 {
if blkiodata.is_empty() {
return m;
}
@ -803,7 +803,7 @@ fn get_blkio_stat_blkiodata(blkiodata: &[BlkIoData]) -> RepeatedField<BlkioStats
fn get_blkio_stat_ioservice(services: &[IoService]) -> RepeatedField<BlkioStatsEntry> {
let mut m = RepeatedField::new();
if services.len() == 0 {
if services.is_empty() {
return m;
}
@ -865,7 +865,7 @@ fn get_blkio_stats(cg: &cgroups::Cgroup) -> SingularPtrField<BlkioStats> {
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?

View File

@ -527,7 +527,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,

View File

@ -134,7 +134,7 @@ fn usernamespace(oci: &Spec) -> Result<()> {
idmapping(&linux.gid_mappings).context("idmapping gid")?;
} 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)));
}
}
@ -239,7 +239,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)));
}

View File

@ -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;
}
@ -410,14 +410,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 = flags | f;
}
None => {
if options.len() > 0 {
if !options.is_empty() {
options.push_str(format!(",{}", opt).as_str());
} else {
options.push_str(format!("{}", opt).as_str());
@ -458,7 +458,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);
}
}

View File

@ -48,7 +48,7 @@ pub fn setup_guest_dns(logger: Logger, dns_list: Vec<String>) -> Result<()> {
fn do_setup_guest_dns(logger: Logger, dns_list: Vec<String>, 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."

View File

@ -630,7 +630,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()];
}
@ -1055,7 +1055,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();
}
@ -1325,7 +1325,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"));
}

View File

@ -183,7 +183,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!(