Skip to content

Commit

Permalink
Merge pull request #5197 from cgwalters/fix-lints
Browse files Browse the repository at this point in the history
tree-wide: `cargo clippy --fix` + a few manual warning fixes
  • Loading branch information
jmarrero authored Dec 20, 2024
2 parents 94b701f + 14dd3de commit 8c19a54
Show file tree
Hide file tree
Showing 34 changed files with 119 additions and 136 deletions.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
16 changes: 8 additions & 8 deletions rust/src/builtins/apply_live.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ fn get_args_variant(sysroot: &ostree::Sysroot, opts: &Opts) -> Result<glib::Vari
if opts.reset {
return Err(anyhow!("Cannot specify both --target and --reset"));
}
r.insert(live::OPT_TARGET, &target.as_str());
r.insert(live::OPT_TARGET, target.as_str());
} else if opts.reset {
let booted = sysroot.require_booted_deployment()?;
// Unwrap safety: This can't return NULL
let csum = booted.csum();
r.insert(live::OPT_TARGET, &csum.as_str());
r.insert(live::OPT_TARGET, csum.as_str());
}

if opts.allow_replacement {
r.insert(live::OPT_REPLACE, &true);
r.insert(live::OPT_REPLACE, true);
}

Ok(r.end())
Expand Down Expand Up @@ -97,15 +97,15 @@ pub(crate) fn applylive_finish(sysroot: &crate::ffi::OstreeSysroot) -> 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"),
)?;

Expand All @@ -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(())
Expand Down
2 changes: 1 addition & 1 deletion rust/src/builtins/compose/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
2 changes: 1 addition & 1 deletion rust/src/builtins/scriptlet_intercept/useradd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)?;
}
}
Expand Down
4 changes: 2 additions & 2 deletions rust/src/builtins/usroverlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) -> 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.
Expand Down
2 changes: 1 addition & 1 deletion rust/src/bwrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions rust/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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());
}
Expand Down
4 changes: 2 additions & 2 deletions rust/src/cliwrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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())?;
Expand Down
2 changes: 1 addition & 1 deletion rust/src/cliwrap/kernel_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion rust/src/cliwrap/yumdnf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl RebaseCmd {
}

fn run_clean(argv: &Vec<String>) -> Result<RunDisposition> {
let arg = if let Some(subarg) = argv.get(0) {
let arg = if let Some(subarg) = argv.first() {
subarg
} else {
anyhow::bail!("Missing required argument");
Expand Down
21 changes: 9 additions & 12 deletions rust/src/compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ impl Default for OutputFormat {
}
}

impl Into<ostree_container::Transport> for OutputFormat {
fn into(self) -> ostree_container::Transport {
match self {
impl From<OutputFormat> 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,
Expand Down Expand Up @@ -279,7 +279,7 @@ pub(crate) fn compose_image(args: Vec<String>) -> CxxResult<()> {
}

let s = self_command()
.args(&[
.args([
"compose",
"tree",
"--unified-core",
Expand All @@ -292,8 +292,8 @@ pub(crate) fn compose_image(args: Vec<String>) -> 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()?;
Expand Down Expand Up @@ -336,18 +336,15 @@ pub(crate) fn compose_image(args: Vec<String>) -> 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() {
Expand Down
27 changes: 11 additions & 16 deletions rust/src/composepost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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())?;
Expand All @@ -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() {
Expand Down Expand Up @@ -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"]);
Expand Down Expand Up @@ -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))?;
}

Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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()?;
Expand All @@ -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();
Expand All @@ -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()?;
Expand Down
2 changes: 1 addition & 1 deletion rust/src/console_progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 8c19a54

Please sign in to comment.