Skip to content

Commit

Permalink
Convert to let-else syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
HuijingHei committed Sep 20, 2024
1 parent 870332c commit 68ec4a8
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 22 deletions.
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

0 comments on commit 68ec4a8

Please sign in to comment.