Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/blockdev/src/blockdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Device {

#[allow(dead_code)]
pub fn has_children(&self) -> bool {
self.children.as_ref().map_or(false, |v| !v.is_empty())
self.children.as_ref().is_some_and(|v| !v.is_empty())
}

// The "start" parameter was only added in a version of util-linux that's only
Expand Down Expand Up @@ -451,7 +451,7 @@ mod test {
#[test]
fn test_parse_lsblk() {
let fixture = include_str!("../tests/fixtures/lsblk.json");
let devs: DevicesOutput = serde_json::from_str(&fixture).unwrap();
let devs: DevicesOutput = serde_json::from_str(fixture).unwrap();
let dev = devs.blockdevices.into_iter().next().unwrap();
let children = dev.children.as_deref().unwrap();
assert_eq!(children.len(), 3);
Expand Down Expand Up @@ -498,7 +498,7 @@ mod test {
}
}
"# };
let table: SfDiskOutput = serde_json::from_str(&fixture).unwrap();
let table: SfDiskOutput = serde_json::from_str(fixture).unwrap();
assert_eq!(
table.partitiontable.find("/dev/loop0p2").unwrap().size,
20961247
Expand Down
5 changes: 1 addition & 4 deletions crates/lib/src/cfsctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,7 @@ enum Command {
}

fn verity_opt(opt: &Option<String>) -> Result<Option<Sha512HashValue>> {
Ok(opt
.as_ref()
.map(|value| FsVerityHashValue::from_hex(value))
.transpose()?)
Ok(opt.as_ref().map(FsVerityHashValue::from_hex).transpose()?)
}

pub(crate) async fn run_from_iter<I>(system_store: &crate::store::Storage, args: I) -> Result<()>
Expand Down
12 changes: 2 additions & 10 deletions crates/lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,17 +921,9 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> {

// If there's no specified image, let's be nice and check if the booted system is using rpm-ostree
if imgref.is_none() {
let booted_incompatible = host
.status
.booted
.as_ref()
.map_or(false, |b| b.incompatible);
let booted_incompatible = host.status.booted.as_ref().is_some_and(|b| b.incompatible);

let staged_incompatible = host
.status
.staged
.as_ref()
.map_or(false, |b| b.incompatible);
let staged_incompatible = host.status.staged.as_ref().is_some_and(|b| b.incompatible);

if booted_incompatible || staged_incompatible {
return Err(anyhow::anyhow!(
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ async fn handle_layer_progress_print(
subtask = SubTaskBytes {
subtask: layer_type.into(),
description: format!("{layer_type}: {short_digest}").clone().into(),
id: format!("{short_digest}").clone().into(),
id: short_digest.to_string().clone().into(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The .clone() here is redundant. short_digest.to_string() creates a new String, and .into() can consume it directly to create the Cow<'t, str>. You can simplify this line. The same applies to the description field on the line above.

Suggested change
id: short_digest.to_string().clone().into(),
id: short_digest.to_string().into(),

bytes_cached: 0,
bytes: 0,
bytes_total: layer_size,
Expand Down
1 change: 0 additions & 1 deletion crates/lib/src/fsck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ async fn verity_state_of_all_objects(
.map_err(|_| anyhow::anyhow!("Invalid UTF-8"))?;

let objdir = ent.open_dir()?;
let expected = expected.clone();
joinset.spawn_blocking(move || verity_state_of_objects(&objdir, name.as_str(), expected));
}

Expand Down
2 changes: 1 addition & 1 deletion crates/lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ async fn install_to_filesystem_impl(
if matches!(cleanup, Cleanup::TriggerOnNextBoot) {
let sysroot_dir = crate::utils::sysroot_dir(ostree)?;
tracing::debug!("Writing {DESTRUCTIVE_CLEANUP}");
sysroot_dir.atomic_write(format!("etc/{}", DESTRUCTIVE_CLEANUP), b"")?;
sysroot_dir.atomic_write(format!("etc/{DESTRUCTIVE_CLEANUP}"), b"")?;
}

// We must drop the sysroot here in order to close any open file
Expand Down
22 changes: 11 additions & 11 deletions crates/lib/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ impl Lint {
f: LintFn,
) -> Self {
Lint {
name: name,
name,
ty: LintType::Fatal,
f: LintFnTy::Regular(f),
description: description,
description,
root_type: None,
}
}
Expand All @@ -169,10 +169,10 @@ impl Lint {
f: LintFn,
) -> Self {
Lint {
name: name,
name,
ty: LintType::Warning,
f: LintFnTy::Regular(f),
description: description,
description,
root_type: None,
}
}
Expand Down Expand Up @@ -290,7 +290,7 @@ fn lint_inner<'skip>(
results.push((lint, f(&root, &config)));
}

let mut recursive_lints = BTreeSet::from_iter(recursive_lints.into_iter());
let mut recursive_lints = BTreeSet::from_iter(recursive_lints);
let mut recursive_errors = BTreeMap::new();
root.walk(
&WalkConfiguration::default()
Expand Down Expand Up @@ -327,7 +327,7 @@ fn lint_inner<'skip>(
},
)?;
// Extend our overall result set with the recursive-lint errors.
results.extend(recursive_errors.into_iter().map(|(lint, e)| (lint, e)));
results.extend(recursive_errors);
// Any recursive lint still in this list succeeded.
results.extend(recursive_lints.into_iter().map(|lint| (lint, lint_ok())));
for (lint, r) in results {
Expand Down Expand Up @@ -511,7 +511,7 @@ fn check_utf8(e: &WalkComponent, _config: &LintExecutionConfig) -> LintRecursive

if e.file_type.is_symlink() {
let target = e.dir.read_link_contents(filename)?;
if !target.to_str().is_some() {
if target.to_str().is_none() {
return lint_err(format!(
"{}: Found non-utf8 symlink target",
PathQuotedDisplay::new(&path)
Expand Down Expand Up @@ -754,7 +754,7 @@ Any content here in the container image will be masked at runtime.
);
fn check_boot(root: &Dir, config: &LintExecutionConfig) -> LintResult {
let Some(d) = root.open_dir_optional("boot")? else {
return lint_err(format!("Missing /boot directory"));
return lint_err("Missing /boot directory");
};

// First collect all entries to determine if the directory is empty
Expand Down Expand Up @@ -1161,7 +1161,7 @@ mod tests {
output_str.clear();

// Test case 2: Iterator with one item
let items_one = vec!["item1"];
let items_one = ["item1"];
format_items(&config, header, items_one.iter(), &mut output_str)?;
assert_eq!(output_str, "Test Header:\n item1\n");
output_str.clear();
Expand Down Expand Up @@ -1194,7 +1194,7 @@ mod tests {
output_str.clear();

// Test case 2: Iterator with fewer items than DEFAULT_TRUNCATED_OUTPUT
let items_few = vec!["item1", "item2"];
let items_few = ["item1", "item2"];
format_items(&config, header, items_few.iter(), &mut output_str)?;
assert_eq!(output_str, "Test Header:\n item1\n item2\n");
output_str.clear();
Expand Down Expand Up @@ -1246,7 +1246,7 @@ mod tests {
let header = "Numbers";
let mut output_str = String::new();

let items_numbers = vec![1, 2, 3];
let items_numbers = [1, 2, 3];
format_items(&config, header, items_numbers.iter(), &mut output_str)?;
similar_asserts::assert_eq!(output_str, "Numbers:\n 1\n 2\n 3\n");

Expand Down
3 changes: 1 addition & 2 deletions crates/lib/src/podstorage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn bind_storage_roots(cmd: &mut Command, storage_root: &Dir, run_root: &Dir) ->
fn new_podman_cmd_in(storage_root: &Dir, run_root: &Dir) -> Result<Command> {
let mut cmd = Command::new("podman");
bind_storage_roots(&mut cmd, storage_root, run_root)?;
let run_root = format!("/proc/self/fd/{}", STORAGE_RUN_FD);
let run_root = format!("/proc/self/fd/{STORAGE_RUN_FD}");
cmd.args(["--root", STORAGE_ALIAS_DIR, "--runroot", run_root.as_str()]);
Ok(cmd)
}
Expand Down Expand Up @@ -288,7 +288,6 @@ impl CStorage {
Ok(r)
})
.await?
.map_err(Into::into)
}

#[context("Pruning")]
Expand Down
4 changes: 2 additions & 2 deletions crates/lib/src/progress_jsonl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl ProgressWriter {
/// Send an event.
pub(crate) async fn send(&self, event: Event<'_>) {
if let Err(e) = self.send_impl(event, true).await {
eprintln!("Failed to write to jsonl: {}", e);
eprintln!("Failed to write to jsonl: {e}");
// Stop writing to fd but let process continue
// SAFETY: Propagating panics from the mutex here is intentional
let _ = self.inner.lock().await.take();
Expand All @@ -258,7 +258,7 @@ impl ProgressWriter {
/// Send an event that can be dropped.
pub(crate) async fn send_lossy(&self, event: Event<'_>) {
if let Err(e) = self.send_impl(event, false).await {
eprintln!("Failed to write to jsonl: {}", e);
eprintln!("Failed to write to jsonl: {e}");
// Stop writing to fd but let process continue
// SAFETY: Propagating panics from the mutex here is intentional
let _ = self.inner.lock().await.take();
Expand Down
22 changes: 10 additions & 12 deletions crates/lib/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ pub struct ImageReference {
/// If the reference is in :tag@digest form, strip the tag.
fn canonicalize_reference(reference: Reference) -> Option<Reference> {
// No tag? Just pass through.
if reference.tag().is_none() {
return None;
}
reference.tag()?;

// No digest? Also pass through.
let Some(digest) = reference.digest() else {
Expand Down Expand Up @@ -126,7 +124,7 @@ impl ImageReference {
transport: self.transport.clone(),
signature: self.signature.clone(),
};
return Ok(r);
Ok(r)
}
_ => {
// For other transports, we don't do any canonicalization
Expand Down Expand Up @@ -349,14 +347,14 @@ mod tests {
let test_cases = [
// When both a tag and digest are present, the digest should be used
(
format!("quay.io/example/someimage:latest@{}", sample_digest),
format!("quay.io/example/someimage@{}", sample_digest),
format!("quay.io/example/someimage:latest@{sample_digest}"),
format!("quay.io/example/someimage@{sample_digest}"),
"registry",
),
// When only a digest is present, it should be used
(
format!("quay.io/example/someimage@{}", sample_digest),
format!("quay.io/example/someimage@{}", sample_digest),
format!("quay.io/example/someimage@{sample_digest}"),
format!("quay.io/example/someimage@{sample_digest}"),
"registry",
),
// When only a tag is present, it should be preserved
Expand Down Expand Up @@ -385,13 +383,13 @@ mod tests {
),
// Other cases are not canonicalized
(
format!("quay.io/example/someimage:latest@{}", sample_digest),
format!("quay.io/example/someimage:latest@{}", sample_digest),
format!("quay.io/example/someimage:latest@{sample_digest}"),
format!("quay.io/example/someimage:latest@{sample_digest}"),
"containers-storage",
),
(
format!("/path/to/dir:latest"),
format!("/path/to/dir:latest"),
"/path/to/dir:latest".to_string(),
"/path/to/dir:latest".to_string(),
"oci",
),
(
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ fn human_render_slot(
write_row_name(&mut out, "Signature", prefix_len)?;
match signature {
crate::spec::ImageSignature::OstreeRemote(remote) => {
writeln!(out, "ostree-remote:{}", remote)?;
writeln!(out, "ostree-remote:{remote}")?;
}
crate::spec::ImageSignature::ContainerPolicy => {
writeln!(out, "container-policy")?;
Expand Down
2 changes: 0 additions & 2 deletions crates/lib/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use cap_std_ext::cap_std::fs::{Dir, DirBuilder, DirBuilderExt as _};
use cap_std_ext::dirext::CapStdExtDirExt;
use fn_error_context::context;

use composefs;
use ostree_ext::ostree;
use ostree_ext::sysroot::SysrootLock;
use rustix::fs::Mode;
Expand Down Expand Up @@ -175,6 +174,5 @@ impl Storage {
sysroot_dir
.update_timestamps(std::path::Path::new(BOOTC_ROOT))
.context("update_timestamps")
.map_err(Into::into)
}
}
2 changes: 1 addition & 1 deletion crates/lib/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ where
// We need to handle the case where we aren't connected to
// a tty, so indicatif would show nothing by default.
if pb.is_hidden() {
print!("{}...", msg);
print!("{msg}...");
std::io::stdout().flush().unwrap();
}
let r = f.await;
Expand Down
Loading