diff --git a/build.rs b/build.rs index 404d0c6ec5..83399e5c35 100644 --- a/build.rs +++ b/build.rs @@ -6,7 +6,7 @@ fn detect_fedora_feature() -> Result<()> { return Ok(()); } let p = std::process::Command::new("sh") - .args(&["-c", ". /usr/lib/os-release && echo ${ID}"]) + .args(["-c", ". /usr/lib/os-release && echo ${ID}"]) .stdout(std::process::Stdio::piped()) .output()?; let out = std::str::from_utf8(&p.stdout).ok().map(|s| s.trim()); diff --git a/rust/src/builtins/apply_live.rs b/rust/src/builtins/apply_live.rs index 0816fe1e5f..20f84aee55 100644 --- a/rust/src/builtins/apply_live.rs +++ b/rust/src/builtins/apply_live.rs @@ -32,16 +32,16 @@ fn get_args_variant(sysroot: &ostree::Sysroot, opts: &Opts) -> Result CxxResult } else { let lib_diff = ostree_ext::diff::diff( repo, - &booted_commit, - &live_state.commit.as_str(), + booted_commit, + live_state.commit.as_str(), Some("/usr/lib/systemd/system"), )?; let etc_diff = ostree_ext::diff::diff( repo, - &booted_commit, - &live_state.commit.as_str(), + booted_commit, + live_state.commit.as_str(), Some("/usr/etc/systemd/system"), )?; @@ -129,7 +129,7 @@ pub(crate) fn applylive_finish(sysroot: &crate::ffi::OstreeSysroot) -> CxxResult crate::ffi::output_message( "Successfully updated running filesystem tree; Following services may need to be restarted:"); for service in changed { - crate::ffi::output_message(&format!("{}", service.strip_prefix('/').unwrap())); + crate::ffi::output_message(service.strip_prefix('/').unwrap()); } } Ok(()) diff --git a/rust/src/builtins/compose/mod.rs b/rust/src/builtins/compose/mod.rs index daa487e018..f404bf1079 100644 --- a/rust/src/builtins/compose/mod.rs +++ b/rust/src/builtins/compose/mod.rs @@ -61,7 +61,7 @@ fn legacy_prepare_dev(rootfs: &Dir) -> Result<()> { // file so it can use `fchmod()` which may fail for special things like `/dev/tty`. // We have no concerns about following symlinks because we know we just created // the device and there are no concurrent writers. - rustix::fs::chmodat(&dest_dir.as_fd(), nodename, mode, AtFlags::empty()) + rustix::fs::chmodat(dest_dir.as_fd(), nodename, mode, AtFlags::empty()) .with_context(|| format!("Setting permissions of target {}", nodename))?; } smoketest_dev_null(dest_dir)?; diff --git a/rust/src/builtins/scriptlet_intercept/useradd.rs b/rust/src/builtins/scriptlet_intercept/useradd.rs index 12bc50f65a..132dea60bd 100644 --- a/rust/src/builtins/scriptlet_intercept/useradd.rs +++ b/rust/src/builtins/scriptlet_intercept/useradd.rs @@ -53,7 +53,7 @@ pub(crate) fn entrypoint(args: &[&str]) -> Result<()> { if let Some(groups) = supplementary_groups { for group in groups { crate::builtins::scriptlet_intercept::usermod::generate_sysusers_fragment( - &rootdir, username, &group, + &rootdir, username, group, )?; } } diff --git a/rust/src/builtins/usroverlay.rs b/rust/src/builtins/usroverlay.rs index c8e52b2805..14939f5c10 100644 --- a/rust/src/builtins/usroverlay.rs +++ b/rust/src/builtins/usroverlay.rs @@ -8,8 +8,8 @@ use std::os::unix::prelude::CommandExt; /// Directly exec(ostree admin unlock) - does not return on success. pub fn usroverlay_entrypoint(args: &Vec) -> Result<()> { let exec_err = std::process::Command::new("ostree") - .args(&["admin", "unlock"]) - .args(args.into_iter().skip(1)) + .args(["admin", "unlock"]) + .args(args.iter().skip(1)) .exec(); // This is only reached if the `exec()` above failed; otherwise // execution got transferred to `ostree` at that point. diff --git a/rust/src/bwrap.rs b/rust/src/bwrap.rs index c71a2fb3c2..19eb356e86 100644 --- a/rust/src/bwrap.rs +++ b/rust/src/bwrap.rs @@ -138,7 +138,7 @@ impl Drop for RoFilesMount { return; }; // We need to unmount before letting the tempdir cleanup run. - let success = Command::new(get_fusermount_path().unwrap().to_string()) + let success = Command::new(get_fusermount_path().unwrap()) .arg("-u") .arg(tempdir.path()) .status() diff --git a/rust/src/client.rs b/rust/src/client.rs index d60e3b8ed9..18a6ba7c01 100644 --- a/rust/src/client.rs +++ b/rust/src/client.rs @@ -177,7 +177,7 @@ pub(crate) fn client_start_daemon() -> CxxResult<()> { // invocations against the restart limit, so query the status // first. let activeres = Command::new("systemctl") - .args(&["is-active", "rpm-ostreed"]) + .args(["is-active", "rpm-ostreed"]) .output()?; // Explicitly don't check the error return value, we don't want to // hard fail on it. @@ -188,11 +188,11 @@ pub(crate) fn client_start_daemon() -> CxxResult<()> { return Ok(()); } let res = Command::new("systemctl") - .args(&["--no-ask-password", "start", service]) + .args(["--no-ask-password", "start", service]) .status()?; if !res.success() { let _ = Command::new("systemctl") - .args(&["--no-pager", "status", service]) + .args(["--no-pager", "status", service]) .status(); return Err(anyhow!("{}", res).into()); } diff --git a/rust/src/cliwrap.rs b/rust/src/cliwrap.rs index 1675fab58e..567cd9e42b 100644 --- a/rust/src/cliwrap.rs +++ b/rust/src/cliwrap.rs @@ -45,7 +45,7 @@ pub fn entrypoint(args: &[&str]) -> Result<()> { let args = &args[2..]; // The outer code should always pass us at least one arg. let name = args - .get(0) + .first() .copied() .ok_or_else(|| anyhow!("Missing required argument"))?; // Handle this case early, it's not like the other cliwrap bits. @@ -89,7 +89,7 @@ fn install_to_root(args: &[&str]) -> Result<()> { "cliwrap is deprecated; the replacement path is to get functionality into the relevant upstream projects.", ); let root = args - .get(0) + .first() .map(Utf8Path::new) .ok_or_else(|| anyhow!("Missing required argument: ROOTDIR"))?; let rootdir = &Dir::open_ambient_dir(root, cap_std::ambient_authority())?; diff --git a/rust/src/cliwrap/kernel_install.rs b/rust/src/cliwrap/kernel_install.rs index 5344094c34..8123efafb6 100644 --- a/rust/src/cliwrap/kernel_install.rs +++ b/rust/src/cliwrap/kernel_install.rs @@ -14,7 +14,7 @@ pub(crate) fn main(argv: &[&str]) -> Result<()> { if !ostree_ext::container_utils::is_ostree_container()? { return cliutil::exec_real_binary("kernel-install", argv); } - let is_install = matches!(argv.get(0), Some(&"add")); + let is_install = matches!(argv.first(), Some(&"add")); let modules_path = Utf8Dir::open_ambient_dir("lib/modules", cap_std::ambient_authority())?; //kernel-install is called by kernel-core and kernel-modules cleanup let's make sure we just call dracut once. diff --git a/rust/src/cliwrap/yumdnf.rs b/rust/src/cliwrap/yumdnf.rs index 5d9aa5deec..4aec1b2d44 100644 --- a/rust/src/cliwrap/yumdnf.rs +++ b/rust/src/cliwrap/yumdnf.rs @@ -157,7 +157,7 @@ impl RebaseCmd { } fn run_clean(argv: &Vec) -> Result { - let arg = if let Some(subarg) = argv.get(0) { + let arg = if let Some(subarg) = argv.first() { subarg } else { anyhow::bail!("Missing required argument"); diff --git a/rust/src/compose.rs b/rust/src/compose.rs index 1e63b2d9a0..ee68e68dc8 100644 --- a/rust/src/compose.rs +++ b/rust/src/compose.rs @@ -31,9 +31,9 @@ impl Default for OutputFormat { } } -impl Into for OutputFormat { - fn into(self) -> ostree_container::Transport { - match self { +impl From for ostree_container::Transport { + fn from(val: OutputFormat) -> Self { + match val { OutputFormat::Ociarchive => ostree_container::Transport::OciArchive, OutputFormat::Oci => ostree_container::Transport::OciDir, OutputFormat::Registry => ostree_container::Transport::Registry, @@ -279,7 +279,7 @@ pub(crate) fn compose_image(args: Vec) -> CxxResult<()> { } let s = self_command() - .args(&[ + .args([ "compose", "tree", "--unified-core", @@ -292,8 +292,8 @@ pub(crate) fn compose_image(args: Vec) -> CxxResult<()> { "--cachedir", treecachedir.as_str(), ]) - .args(opt.force_nocache.then(|| "--force-nocache")) - .args(opt.offline.then(|| "--cache-only")) + .args(opt.force_nocache.then_some("--force-nocache")) + .args(opt.offline.then_some("--cache-only")) .args(compose_args_extra) .arg(opt.manifest.as_str()) .status()?; @@ -336,18 +336,15 @@ pub(crate) fn compose_image(args: Vec) -> CxxResult<()> { .transpose()?; let s = self_command() - .args(&["compose", "container-encapsulate"]) + .args(["compose", "container-encapsulate"]) .args(label_args) .args(previous_arg) .args(opt.image_config.map(|v| format!("--image-config={v}"))) - .args(&[ + .args([ "--repo", repo.as_str(), commitid.as_str(), - tempdest - .as_ref() - .map(|s| s.as_str()) - .unwrap_or_else(|| target_imgref.as_str()), + tempdest.as_deref().unwrap_or(target_imgref.as_str()), ]) .status()?; if !s.success() { diff --git a/rust/src/composepost.rs b/rust/src/composepost.rs index 96f2c8d40c..7d9199f22a 100644 --- a/rust/src/composepost.rs +++ b/rust/src/composepost.rs @@ -229,12 +229,7 @@ pub fn compose_prepare_rootfs( compose_init_rootfs_strict( target_rootfs_dfd, tmp_is_dir, - treefile - .parsed - .base - .opt_usrlocal - .clone() - .unwrap_or_default(), + treefile.parsed.base.opt_usrlocal.unwrap_or_default(), )?; println!("Moving /usr to target"); @@ -272,7 +267,7 @@ fn postprocess_useradd(rootfs_dfd: &cap_std::fs::Dir) -> Result<()> { let perms = cap_std::fs::Permissions::from_mode(0o644); if let Some(f) = rootfs_dfd.open_optional(path).context("opening")? { rootfs_dfd - .atomic_replace_with(&path, |bufw| -> Result<_> { + .atomic_replace_with(path, |bufw| -> Result<_> { bufw.get_mut().as_file_mut().set_permissions(perms)?; let f = BufReader::new(&f); for line in f.lines() { @@ -379,7 +374,7 @@ fn postprocess_rpm_macro(rootfs_dfd: &Dir) -> Result<()> { rootfs_dfd.create_dir_with(RPM_MACROS_DIR, &db)?; let rpm_macros_dfd = rootfs_dfd.open_dir(RPM_MACROS_DIR)?; let perms = cap_std::fs::Permissions::from_mode(0o644); - rpm_macros_dfd.atomic_replace_with(&MACRO_FILENAME, |w| -> Result<()> { + rpm_macros_dfd.atomic_replace_with(MACRO_FILENAME, |w| -> Result<()> { w.get_mut().as_file_mut().set_permissions(perms)?; w.write_all(b"%_dbpath /")?; w.write_all(RPMOSTREE_RPMDB_LOCATION.as_bytes())?; @@ -398,7 +393,7 @@ fn postprocess_subs_dist(rootfs_dfd: &Dir) -> Result<()> { let path = Path::new("usr/etc/selinux/targeted/contexts/files/file_contexts.subs_dist"); if let Some(f) = rootfs_dfd.open_optional(path)? { let perms = cap_std::fs::Permissions::from_mode(0o644); - rootfs_dfd.atomic_replace_with(&path, |w| -> Result<()> { + rootfs_dfd.atomic_replace_with(path, |w| -> Result<()> { w.get_mut().as_file_mut().set_permissions(perms)?; let f = BufReader::new(&f); for line in f.lines() { @@ -753,7 +748,7 @@ fn compose_postprocess_mutate_os_release( // of resolving a symlink relative to a rootfs (see discussions in // https://github.com/projectatomic/rpm-ostree/pull/410/) let mut bwrap = crate::bwrap::Bubblewrap::new_with_mutability( - &rootfs, + rootfs, crate::ffi::BubblewrapMutability::Immutable, )?; bwrap.append_child_argv(["realpath", "/etc/os-release"]); @@ -1113,7 +1108,7 @@ pub fn rootfs_prepare_links( .with_context(|| format!("Moving /{} to /{}", &varlib_path, &usrlib_path))?; let target = format!("../../{}", &usrlib_path); - ensure_symlink(&rootfs, &target, &varlib_path) + ensure_symlink(rootfs, &target, &varlib_path) .with_context(|| format!("Creating /{} symlink", &varlib_path))?; } @@ -1255,12 +1250,12 @@ pub fn directory_size(dfd: i32, cancellable: &crate::FFIGCancellable) -> CxxResu let child = d.open_dir(ent.file_name())?; r += directory_size_recurse(&child, cancellable)?; } else if meta.is_file() { - r += meta.size() as u64; + r += meta.size(); } } Ok(r) } - Ok(directory_size_recurse(&dfd, &cancellable)?) + Ok(directory_size_recurse(dfd, &cancellable)?) } #[context("Hardlinking rpmdb to base location")] @@ -1308,7 +1303,7 @@ fn rewrite_rpmdb_for_target_inner(rootfs_dfd: &Dir, normalize: bool) -> Result<( let dbpath_arg = format!("--dbpath=/proc/self/cwd/{}", RPMOSTREE_RPMDB_LOCATION); // Fork rpmdb from the *host* rootfs to read the rpmdb back into memory let r = std::process::Command::new("rpmdb") - .args(&[dbpath_arg.as_str(), "--exportdb"]) + .args([dbpath_arg.as_str(), "--exportdb"]) .current_dir(format!("/proc/self/fd/{}", rootfs_dfd.as_raw_fd())) .stdout(Stdio::from(dbfd.try_clone()?)) .status()?; @@ -1331,7 +1326,7 @@ fn rewrite_rpmdb_for_target_inner(rootfs_dfd: &Dir, normalize: bool) -> Result<( } // Fork the target rpmdb to write the content from memory to disk - let mut bwrap = Bubblewrap::new_with_mutability(&rootfs_dfd, BubblewrapMutability::RoFiles)?; + let mut bwrap = Bubblewrap::new_with_mutability(rootfs_dfd, BubblewrapMutability::RoFiles)?; bwrap.append_child_argv(["rpmdb", dbpath_arg.as_str(), "--importdb"]); bwrap.take_stdin_fd(dbfd.into_raw_fd()); let cancellable = gio::Cancellable::new(); @@ -1342,7 +1337,7 @@ fn rewrite_rpmdb_for_target_inner(rootfs_dfd: &Dir, normalize: bool) -> Result<( // Sometimes we can end up with build-to-build variance in the underlying rpmdb // files. Attempt to sort that out, if requested. if normalize { - normalization::normalize_rpmdb(&rootfs_dfd, RPMOSTREE_RPMDB_LOCATION)?; + normalization::normalize_rpmdb(rootfs_dfd, RPMOSTREE_RPMDB_LOCATION)?; } tempetc.undo()?; diff --git a/rust/src/console_progress.rs b/rust/src/console_progress.rs index 9b8277bf02..2cc30347a2 100644 --- a/rust/src/console_progress.rs +++ b/rust/src/console_progress.rs @@ -197,7 +197,7 @@ pub(crate) fn console_progress_begin_task(msg: &str) { pub(crate) fn console_progress_begin_n_items(msg: &str, n: u64) { let mut lock = PROGRESS.lock().unwrap(); assert_empty(&lock, msg); - *lock = Some(ProgressState::new(msg, ProgressType::NItems(n as u64))); + *lock = Some(ProgressState::new(msg, ProgressType::NItems(n))); } pub(crate) fn console_progress_begin_percent(msg: &str) { diff --git a/rust/src/container.rs b/rust/src/container.rs index ab9f59f499..4c890214bc 100644 --- a/rust/src/container.rs +++ b/rust/src/container.rs @@ -334,7 +334,7 @@ pub fn container_encapsulate(args: Vec) -> CxxResult<()> { .collect(); state.packagemeta.insert(ObjectSourceMeta { identifier: Rc::clone(nevra), - name: Rc::from(libdnf_sys::hy_split_nevra(&nevra)?.name), + name: Rc::from(libdnf_sys::hy_split_nevra(nevra)?.name), srcid: Rc::from(pkgmeta.src_pkg()), change_time_offset, change_frequency: pruned_changelogs.len() as u32, @@ -357,7 +357,7 @@ pub fn container_encapsulate(args: Vec) -> CxxResult<()> { .map_err(anyhow::Error::msg)?; let initramfs = initramfs.downcast_ref::().unwrap(); let checksum = initramfs.checksum(); - let name = format!("initramfs"); + let name = "initramfs".to_string(); let identifier = format!("{} (kernel {})", name, kernel_ver).into_boxed_str(); let identifier = Rc::from(identifier); @@ -486,7 +486,7 @@ pub fn container_encapsulate(args: Vec) -> CxxResult<()> { .previous_build_manifest .as_ref() .map(|p| { - oci_spec::image::ImageManifest::from_file(&p) + oci_spec::image::ImageManifest::from_file(p) .map_err(|e| anyhow::anyhow!("Failed to read previous manifest {p}: {e}")) }) .transpose()?; @@ -524,7 +524,7 @@ pub fn container_encapsulate(args: Vec) -> CxxResult<()> { if let Some(compare_with_build) = opt.compare_with_build.as_ref() { progress_task("Comparing Builds", || { handle.block_on(async { - compare_builds(&compare_with_build, &format!("{}", &opt.imgref)).await + compare_builds(compare_with_build, &format!("{}", &opt.imgref)).await }) })?; }; @@ -547,7 +547,7 @@ struct UpdateFromRunningOpts { // This reimplements https://github.com/ostreedev/ostree/pull/2691 basically #[context("Finding encapsulated commits")] fn find_encapsulated_commits(repo: &Utf8Path) -> Result> { - let objects = Dir::open_ambient_dir(&repo.join("objects"), cap_std::ambient_authority())?; + let objects = Dir::open_ambient_dir(repo.join("objects"), cap_std::ambient_authority())?; let mut r = Vec::new(); for entry in objects.entries()? { let entry = entry?; @@ -612,9 +612,13 @@ pub(crate) fn deploy_from_self_entrypoint(args: Vec) -> CxxResult<()> { let encapsulated_commits = find_encapsulated_commits(src_repo_path)?; let commit = match encapsulated_commits.as_slice() { - [] => return Err(format!("No encapsulated commit found in container").into()), + [] => { + return Err("No encapsulated commit found in container" + .to_string() + .into()) + } [c] => { - ostree::validate_checksum_string(&c)?; + ostree::validate_checksum_string(c)?; c.as_str() } o => return Err(format!("Found {} commit objects, expected just one", o.len()).into()), @@ -627,8 +631,8 @@ pub(crate) fn deploy_from_self_entrypoint(args: Vec) -> CxxResult<()> { let flags = ostree::RepoPullFlags::MIRROR; let opts = glib::VariantDict::new(None); let refs = [commit]; - opts.insert("refs", &&refs[..]); - opts.insert("flags", &(flags.bits() as i32)); + opts.insert("refs", &refs[..]); + opts.insert("flags", flags.bits() as i32); let options = opts.to_variant(); target_repo .pull_with_options( @@ -643,8 +647,8 @@ pub(crate) fn deploy_from_self_entrypoint(args: Vec) -> CxxResult<()> { println!("Imported: {commit}"); let status = Command::new("chroot") - .args(&[opts.target_root.as_str(), "rpm-ostree", "rebase", commit]) - .args(opts.reboot.then(|| "--reboot")) + .args([opts.target_root.as_str(), "rpm-ostree", "rebase", commit]) + .args(opts.reboot.then_some("--reboot")) .status()?; if !status.success() { return Err(format!("Failed to deploy commit: {:?}", status).into()); diff --git a/rust/src/core.rs b/rust/src/core.rs index 69ded654c5..a2e339aa06 100644 --- a/rust/src/core.rs +++ b/rust/src/core.rs @@ -177,7 +177,7 @@ impl FilesystemScriptPrep { pub(crate) fn new(rootfs: Dir) -> Result> { for &path in Self::OPTIONAL_PATHS { if rootfs.try_exists(path)? { - rootfs.rename(path, &rootfs, &Self::saved_name(path))?; + rootfs.rename(path, &rootfs, Self::saved_name(path))?; } } for &(path, contents) in Self::REPLACE_OPTIONAL_PATHS { diff --git a/rust/src/cxxrsutil.rs b/rust/src/cxxrsutil.rs index b985185812..9d231f371f 100644 --- a/rust/src/cxxrsutil.rs +++ b/rust/src/cxxrsutil.rs @@ -39,7 +39,7 @@ pub trait FFIGObjectReWrap<'a> { type ReWrapped; /// Convert a glib-rs wrapper object borrowed cxx-rs type. - fn reborrow_cxx(&'a self) -> &Self::ReWrapped; + fn reborrow_cxx(&'a self) -> &'a Self::ReWrapped; } /// Implement FFIGObjectWrapper given a pair of wrapper type @@ -59,7 +59,7 @@ macro_rules! impl_wrap { impl<'a> FFIGObjectReWrap<'a> for $bound { type ReWrapped = $w; - fn reborrow_cxx(&'a self) -> &Self::ReWrapped { + fn reborrow_cxx(&'a self) -> &'a Self::ReWrapped { let p: *const $sys = self.to_glib_none().0; let p = p as *const Self::ReWrapped; unsafe { &*p } diff --git a/rust/src/daemon.rs b/rust/src/daemon.rs index dbb4d39eac..0258ea4715 100644 --- a/rust/src/daemon.rs +++ b/rust/src/daemon.rs @@ -103,17 +103,17 @@ fn deployment_populate_variant_origin( // Initramfs data. if let Some(initramfs) = tf.derive.initramfs.as_ref() { - dict.insert("regenerate-initramfs", &initramfs.regenerate); + dict.insert("regenerate-initramfs", initramfs.regenerate); vdict_insert_optvec(dict, "initramfs-args", initramfs.args.as_ref()); vdict_insert_optset(dict, "initramfs-etc", initramfs.etc.as_ref()); } else { // This key is also always injected. - dict.insert("regenerate-initramfs", &false); + dict.insert("regenerate-initramfs", false); } // Other bits. if tf.cliwrap.unwrap_or_default() { - dict.insert("cliwrap", &true); + dict.insert("cliwrap", true); } Ok(()) @@ -134,41 +134,41 @@ pub(crate) fn deployment_populate_variant( // First, basic values from ostree dict.insert("id", &id); - dict.insert("osname", &deployment.osname().as_str()); - dict.insert("checksum", &deployment.csum().as_str()); - dict.insert_value("serial", &(deployment.deployserial() as i32).to_variant()); + dict.insert("osname", deployment.osname().as_str()); + dict.insert("checksum", deployment.csum().as_str()); + dict.insert_value("serial", &deployment.deployserial().to_variant()); let booted: bool = sysroot .booted_deployment() .map(|b| b.equal(deployment)) .unwrap_or_default(); - dict.insert("booted", &booted); + dict.insert("booted", booted); let live_state = crate::live::get_live_apply_state(sysroot.reborrow_cxx(), deployment.reborrow_cxx())?; if !live_state.inprogress.is_empty() { - dict.insert("live-inprogress", &live_state.inprogress.as_str()); + dict.insert("live-inprogress", live_state.inprogress.as_str()); } if !live_state.commit.is_empty() { - dict.insert("live-replaced", &live_state.commit.as_str()); + dict.insert("live-replaced", live_state.commit.as_str()); } /* Staging status */ - dict.insert("staged", &deployment.is_staged()); + dict.insert("staged", deployment.is_staged()); if deployment.is_staged() // XXX: this should check deployment.is_finalization_locked() too now // but the libostree Rust bindings need to be updated && std::path::Path::new("/run/ostree/staged-deployment-locked").exists() { - dict.insert("finalization-locked", &true); + dict.insert("finalization-locked", true); } - dict.insert("pinned", &deployment.is_pinned()); + dict.insert("pinned", deployment.is_pinned()); let unlocked = deployment.unlocked(); // Unwrap safety: This always returns a value dict.insert( "unlocked", - &ostree::Deployment::unlocked_state_to_string(unlocked).as_str(), + ostree::Deployment::unlocked_state_to_string(unlocked).as_str(), ); // Some of the origin-based state. But not all yet; see the rest of the @@ -282,7 +282,7 @@ pub(crate) fn variant_add_remote_status( false }; - dict.insert("gpg-enabled", &gpg_verify); + dict.insert("gpg-enabled", gpg_verify); if !gpg_verify { return Ok(()); // note early return; no need to verify signatures! } @@ -344,9 +344,9 @@ fn get_cached_signatures_variant( sigs.push(glib::Variant::from_variant(&verify_result.all(i))); // we know index is in range } - let v = glib::Variant::array_from_iter_with_type(&*glib::Variant::static_variant_type(), sigs); + let v = glib::Variant::array_from_iter_with_type(&glib::Variant::static_variant_type(), sigs); let perms = cap_std::fs::Permissions::from_mode(0o600); - cachedir.atomic_write_with_perms(&cached_relpath, &v.data_as_bytes(), perms)?; + cachedir.atomic_write_with_perms(&cached_relpath, v.data_as_bytes(), perms)?; Ok(v) } @@ -450,7 +450,7 @@ pub fn generate_baselayer_refs( // Regenerate the refs from the base commits. let bases = sysroot.deployments().into_iter().filter_map(|deployment| { deployment_layeredmeta_load_commit(&repo, &deployment) - .map(|meta| meta.is_layered.then(|| meta.base_commit)) + .map(|meta| meta.is_layered.then_some(meta.base_commit)) .transpose() }); for (index, base_rev) in bases.enumerate() { diff --git a/rust/src/deployment_utils.rs b/rust/src/deployment_utils.rs index f4663341e3..a52b4b6177 100644 --- a/rust/src/deployment_utils.rs +++ b/rust/src/deployment_utils.rs @@ -115,5 +115,5 @@ pub fn deployment_add_manifest_diff( diffv.insert("n-added", diff.n_added); diffv.insert("added-size", diff.added_size); dict.insert("manifest-diff", diffv); - return true; + true } diff --git a/rust/src/extensions.rs b/rust/src/extensions.rs index 3b8bce9444..7de0d2084e 100644 --- a/rust/src/extensions.rs +++ b/rust/src/extensions.rs @@ -47,17 +47,13 @@ pub struct Extension { #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] #[serde(rename_all = "kebab-case")] +#[derive(Default)] enum ExtensionKind { + #[default] OsExtension, Development, } -impl Default for ExtensionKind { - fn default() -> Self { - ExtensionKind::OsExtension - } -} - fn extensions_load_stream( stream: &mut impl std::io::Read, basearch: &str, diff --git a/rust/src/fedora_integration.rs b/rust/src/fedora_integration.rs index d94eebfafa..108af53887 100644 --- a/rust/src/fedora_integration.rs +++ b/rust/src/fedora_integration.rs @@ -230,7 +230,7 @@ fn get_base_package_list() -> Result> { sysroot.load(gio::Cancellable::NONE)?; let deployments = sysroot.deployments(); let default = deployments - .get(0) + .first() .ok_or_else(|| anyhow::anyhow!("No deployments found"))?; let checksum = default.csum(); let repo = sysroot.repo(); diff --git a/rust/src/fsutil.rs b/rust/src/fsutil.rs index 4c92540d86..32a5c74ef4 100644 --- a/rust/src/fsutil.rs +++ b/rust/src/fsutil.rs @@ -27,15 +27,15 @@ impl ResolvedOstreePaths { /// Returns a pair of the resolved path and in the case where /// the path points to a symlink, it also includes the resolved /// symlink target. -pub fn resolve_ostree_paths<'a>( +pub fn resolve_ostree_paths( path: &Utf8Path, fsroot: &ostree::RepoFile, - cache: &'a mut HashMap, + cache: &mut HashMap, ) -> Option { assert!(path.is_absolute()); // Recurse until root - if path.parent() == None { + if path.parent().is_none() { return Some(ResolvedOstreePaths { path: fsroot.clone(), symlink_target: None, @@ -48,11 +48,7 @@ pub fn resolve_ostree_paths<'a>( } // Resolve our parent - let parent = if let Some(parent) = resolve_ostree_paths(path.parent().unwrap(), fsroot, cache) { - parent - } else { - return None; - }; + let parent = resolve_ostree_paths(path.parent().unwrap(), fsroot, cache)?; // Resolve ourselves from our parent let child_file = parent @@ -113,7 +109,7 @@ pub fn resolve_ostree_paths<'a>( cache.insert(path.to_owned(), result.clone()); } - return Some(result); + Some(result) } pub trait FileHelpers { diff --git a/rust/src/importer.rs b/rust/src/importer.rs index dea0dabc02..2b9e87c15d 100644 --- a/rust/src/importer.rs +++ b/rust/src/importer.rs @@ -338,7 +338,7 @@ fn tweak_imported_file_info(file_info: &FileInfo, ro_executables: bool) { // https://github.com/fedora-sysv/chkconfig/pull/67 propagates everywhere // and/or https://github.com/ostreedev/ostree-rs-ext/pull/182 merges. if target.ends_with("//sbin/chkconfig") { - let canonicalized = &canonicalize_path(&target); + let canonicalized = &canonicalize_path(target); file_info.set_symlink_target(canonicalized); } } diff --git a/rust/src/initramfs.rs b/rust/src/initramfs.rs index 465ef068f1..da8f9ea9cb 100644 --- a/rust/src/initramfs.rs +++ b/rust/src/initramfs.rs @@ -100,7 +100,7 @@ fn generate_initramfs_overlay>( // Yeah, we need an initramfs-making crate. See also // https://github.com/dracutdevs/dracut/commit/a9c6704 let mut cmd = std::process::Command::new("/bin/bash"); - cmd.args(&[ + cmd.args([ "-c", "set -euo pipefail; cpio --create --format newc --quiet --reproducible --null | gzip -1", ]); @@ -193,11 +193,11 @@ pub(crate) fn run_dracut(kernel_dir: &str) -> Result<()> { let cliwrap_dracut = Utf8Path::new(crate::cliwrap::CLIWRAP_DESTDIR).join("dracut"); let dracut_path = cliwrap_dracut .exists() - .then(|| cliwrap_dracut) + .then_some(cliwrap_dracut) .unwrap_or_else(|| Utf8Path::new("dracut").to_owned()); // If changing this, also look at changing rpmostree-kernel.cxx let res = Command::new(dracut_path) - .args(&[ + .args([ "--no-hostonly", "--kver", kernel_dir, @@ -216,7 +216,6 @@ pub(crate) fn run_dracut(kernel_dir: &str) -> Result<()> { )); } let f = std::fs::OpenOptions::new() - .write(true) .append(true) .open(&tmp_initramfs_path)?; crate::initramfs::append_dracut_random_cpio(f.as_raw_fd())?; diff --git a/rust/src/isolation.rs b/rust/src/isolation.rs index cfc55672bb..9477c89b4e 100644 --- a/rust/src/isolation.rs +++ b/rust/src/isolation.rs @@ -68,7 +68,7 @@ pub(crate) fn unprivileged_subprocess(binary: &str) -> Command { return Command::new(binary); } let mut cmd = Command::new("setpriv"); - cmd.args(&[ + cmd.args([ "--no-new-privs", "--init-groups", "--reuid", diff --git a/rust/src/journal.rs b/rust/src/journal.rs index b2a03c82c8..68475022ed 100644 --- a/rust/src/journal.rs +++ b/rust/src/journal.rs @@ -81,7 +81,7 @@ fn impl_journal_print_staging_failure() -> Result<()> { j.match_add("_PID", ostree_pid.as_str())?; j.match_add("_BOOT_ID", previous_boot_id.as_str())?; - if j.next_entry()? != None { + if (j.next_entry()?).is_some() { return Ok(()); // finished successfully! } diff --git a/rust/src/kickstart.rs b/rust/src/kickstart.rs index 5c9ab7d752..1bdd208ea2 100644 --- a/rust/src/kickstart.rs +++ b/rust/src/kickstart.rs @@ -58,14 +58,14 @@ fn filtermap_line(line: &str) -> Option<&str> { impl Packages { fn parse<'a, 'b>( args: impl Iterator, - mut lines: impl Iterator, + lines: impl Iterator, ) -> Result { // Ensure there's an argv0 let args = [PACKAGES].into_iter().chain(args); let args = PackageArgs::try_parse_from(args)?; let mut install = Vec::new(); let mut excludes = Vec::new(); - while let Some(line) = lines.next() { + for line in lines { let line = line.trim(); if line == END { return Ok(Self { diff --git a/rust/src/lib.rs b/rust/src/lib.rs index a0e2aed0b6..ddbd2ee770 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -508,7 +508,7 @@ pub mod ffi { type TokioEnterGuard<'a>; fn tokio_handle_get() -> Box; - unsafe fn enter(self: &TokioHandle) -> Box; + fn enter(self: &TokioHandle) -> Box; } // scripts.rs diff --git a/rust/src/live.rs b/rust/src/live.rs index 1d0517f743..00cbd04839 100644 --- a/rust/src/live.rs +++ b/rust/src/live.rs @@ -61,7 +61,7 @@ pub(crate) fn get_live_state( deploy: &ostree::Deployment, ) -> Result> { let run = Dir::open_ambient_dir("/run", cap_std::ambient_authority())?; - if !run.try_exists(&get_runstate_dir(deploy).join(LIVE_STATE_NAME))? { + if !run.try_exists(get_runstate_dir(deploy).join(LIVE_STATE_NAME))? { return Ok(None); } let live_commit = repo.resolve_rev(LIVE_REF, true)?; @@ -79,7 +79,7 @@ fn write_live_state( state: &LiveApplyState, ) -> Result<()> { let run = Dir::open_ambient_dir("/run", cap_std::ambient_authority())?; - let rundir = if let Some(d) = run.open_dir_optional(&get_runstate_dir(deploy))? { + let rundir = if let Some(d) = run.open_dir_optional(get_runstate_dir(deploy))? { d } else { return Ok(()); diff --git a/rust/src/passwd.rs b/rust/src/passwd.rs index 213c271c7e..02709c0605 100644 --- a/rust/src/passwd.rs +++ b/rust/src/passwd.rs @@ -353,17 +353,17 @@ enum PasswdKind { impl PasswdKind { // Get user/group passwd file fn passwd_file(&self) -> &'static str { - return match *self { + match *self { PasswdKind::User => "passwd", PasswdKind::Group => "group", - }; + } } // Get user/group shadow file fn shadow_file(&self) -> &'static str { - return match *self { + match *self { PasswdKind::User => "shadow", PasswdKind::Group => "gshadow", - }; + } } } diff --git a/rust/src/sysroot_upgrade.rs b/rust/src/sysroot_upgrade.rs index 7266989104..3c2081faaa 100644 --- a/rust/src/sysroot_upgrade.rs +++ b/rust/src/sysroot_upgrade.rs @@ -95,8 +95,8 @@ fn default_container_pull_config(imgref: &OstreeImageReference) -> Result Result<()> { // A new mount namespace should have been created for us let r = Command::new("mount") - .args(&["-o", "remount,rw", "/sysroot"]) + .args(["-o", "remount,rw", "/sysroot"]) .status()?; if !r.success() { anyhow::bail!("Failed to remount /sysroot"); @@ -196,13 +196,13 @@ fn update_os_tree(opts: &SyntheticUpgradeOpts) -> Result<()> { let src_ref = opts.src_ref.as_deref().unwrap_or(opts.ostref.as_str()); let mut cmd = Command::new("ostree"); cmd.arg(format!("--repo={}", repo_path.to_str().unwrap())) - .args(&["commit", "--consume", "-b"]) + .args(["commit", "--consume", "-b"]) .arg(opts.ostref.as_str()) .args(&[ format!("--base={}", src_ref), format!("--tree=dir={}", tmp_rootfs.to_str().unwrap()), ]) - .args(&[ + .args([ "--owner-uid=0", "--owner-gid=0", "--selinux-policy-from-base", diff --git a/rust/src/tmpfiles.rs b/rust/src/tmpfiles.rs index 2dabe0dc6e..46412e1358 100644 --- a/rust/src/tmpfiles.rs +++ b/rust/src/tmpfiles.rs @@ -67,7 +67,7 @@ pub fn deduplicate_tmpfiles_entries(tmprootfs_dfd: i32) -> CxxResult<()> { } let perms = Permissions::from_mode(0o644); - tmpfiles_dir.atomic_write_with_perms(&AUTOVAR_PATH, entries.as_bytes(), perms)?; + tmpfiles_dir.atomic_write_with_perms(AUTOVAR_PATH, entries.as_bytes(), perms)?; } Ok(()) } diff --git a/rust/src/treefile.rs b/rust/src/treefile.rs index ba18601474..32a8ec3549 100644 --- a/rust/src/treefile.rs +++ b/rust/src/treefile.rs @@ -238,7 +238,7 @@ fn take_archful_pkgs( if let Some(basearch) = basearch { if basearch == &key["packages-".len()..] { - assert!(archful_pkgs == None); + assert!(archful_pkgs.is_none()); archful_pkgs = Some( treefile.base.extra[key] .as_array() @@ -353,11 +353,11 @@ fn treefile_parse>( BTreeMap::new() }; let passwd = match tf.get_check_passwd() { - CheckPasswd::File(ref f) => load_passwd_file(&parent, f)?, + CheckPasswd::File(ref f) => load_passwd_file(parent, f)?, _ => None, }; let group = match tf.get_check_groups() { - CheckGroups::File(ref f) => load_passwd_file(&parent, f)?, + CheckGroups::File(ref f) => load_passwd_file(parent, f)?, _ => None, }; @@ -850,12 +850,12 @@ impl Treefile { let packages = self.filter_package_requests(packages, false, allow_existing)?; let set = self.parsed.packages.ext_get_or_insert_default(); let n = set.len(); - set.extend(packages.into_iter()); + set.extend(packages); Ok(set.len() != n) } pub(crate) fn enable_repo(&mut self, repo: &str) -> Result<()> { - let repos = self.parsed.base.repos.get_or_insert_with(|| Vec::new()); + let repos = self.parsed.base.repos.get_or_insert_with(Vec::new); repos.extend(repo.split(',').map(ToOwned::to_owned)); Ok(()) } @@ -1384,7 +1384,7 @@ impl Treefile { .releasever .as_ref() .map(|rv| rv.to_string()) - .unwrap_or_else(|| "".to_string()) + .unwrap_or_default() } pub(crate) fn get_container_cmd(&self) -> Vec { @@ -2054,7 +2054,7 @@ fn split_whitespace_unless_quoted(element: &str) -> Result Result Result Self { - BootLocation::New - } -} - #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] #[serde(rename_all = "kebab-case")] #[serde(tag = "type")] diff --git a/rust/src/utils.rs b/rust/src/utils.rs index 4930b1912e..cb19dd3d8c 100644 --- a/rust/src/utils.rs +++ b/rust/src/utils.rs @@ -183,7 +183,7 @@ where /// a mapping. pub fn decompose_sha256_nevra(v: &str) -> Result<(&str, &str)> { let parts: Vec<&str> = v.splitn(2, ':').collect(); - match (parts.get(0), parts.get(1)) { + match (parts.first(), parts.get(1)) { (Some(_), None) => bail!("Missing : in {}", v), (Some(sha256), Some(nevra)) => { ostree::validate_checksum_string(sha256)?; @@ -557,7 +557,7 @@ pub(crate) fn impl_sealed_memfd(description: &str, content: &[u8]) -> Result(); - (&*mfd_file).set_len(content.len() as u64)?; + mfd_file.set_len(content.len() as u64)?; (&*mfd_file).write_all(content)?; (&*mfd_file).seek(std::io::SeekFrom::Start(0))?; }