Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to let-else syntax #730

Merged
merged 1 commit into from
Sep 20, 2024
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
4 changes: 1 addition & 3 deletions src/bios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ impl Component for Bios {
device: &str,
_update_firmware: bool,
) -> Result<InstalledContent> {
let meta = if let Some(meta) = get_component_update(src_root, self)? {
meta
} else {
let Some(meta) = get_component_update(src_root, self)? else {
anyhow::bail!("No update metadata for component {} found", self.name());
};

Expand Down
10 changes: 3 additions & 7 deletions src/bootupd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,7 @@ pub(crate) fn adopt_and_update(name: &str) -> Result<ContentMetadata> {

ensure_writable_boot()?;

let update = if let Some(update) = component.query_update(&sysroot)? {
update
} else {
let Some(update) = component.query_update(&sysroot)? else {
anyhow::bail!("Component {} has no available update", name);
};
let mut state_guard =
Expand All @@ -270,12 +268,10 @@ pub(crate) fn adopt_and_update(name: &str) -> Result<ContentMetadata> {
pub(crate) fn validate(name: &str) -> Result<ValidationResult> {
let state = SavedState::load_from_disk("/")?.unwrap_or_default();
let component = component::new_from_name(name)?;
let inst = if let Some(inst) = state.installed.get(name) {
inst.clone()
} else {
let Some(inst) = state.installed.get(name) else {
anyhow::bail!("Component {} is not installed", name);
};
component.validate(&inst)
component.validate(inst)
}

pub(crate) fn status() -> Result<Status> {
Expand Down
4 changes: 1 addition & 3 deletions src/efi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,7 @@ impl Component for Efi {
device: &str,
update_firmware: bool,
) -> Result<InstalledContent> {
let meta = if let Some(meta) = get_component_update(src_root, self)? {
meta
} else {
let Some(meta) = get_component_update(src_root, self)? else {
anyhow::bail!("No update metadata for component {} found", self.name());
};
log::debug!("Found metadata {}", meta.version);
Expand Down
8 changes: 2 additions & 6 deletions src/filetree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ impl FileTree {
let mut ret = HashMap::new();
for entry in dir.list_dir(".")? {
let entry = entry?;
let name = if let Some(name) = entry.file_name().to_str() {
name
} else {
let Some(name) = entry.file_name().to_str() else {
bail!("Invalid UTF-8 filename: {:?}", entry.file_name())
};
if name.starts_with(TMP_PREFIX) {
Expand Down Expand Up @@ -239,9 +237,7 @@ impl FileTree {
fn cleanup_tmp(dir: &openat::Dir) -> Result<()> {
for entry in dir.list_dir(".")? {
let entry = entry?;
let name = if let Some(name) = entry.file_name().to_str() {
name
} else {
let Some(name) = entry.file_name().to_str() else {
// Skip invalid UTF-8 for now, we will barf on it later though.
continue;
};
Expand Down
4 changes: 1 addition & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ pub(crate) fn filenames(dir: &openat::Dir) -> Result<HashSet<String>> {
let mut ret = HashSet::new();
for entry in dir.list_dir(".")? {
let entry = entry?;
let name = if let Some(name) = entry.file_name().to_str() {
name
} else {
let Some(name) = entry.file_name().to_str() else {
bail!("Invalid UTF-8 filename: {:?}", entry.file_name())
};
match dir.get_file_type(&entry)? {
Expand Down
Loading