Skip to content

Commit 8ff0a95

Browse files
Update src/utils/mobile_app/apple.rs
Co-authored-by: Daniel Szoke <[email protected]>
1 parent 0eeaa67 commit 8ff0a95

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/utils/mobile_app/apple.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,18 @@ pub fn ipa_to_xcarchive(ipa_path: &Path, ipa_bytes: &[u8], temp_dir: &TempDir) -
136136
Ok(xcarchive_dir)
137137
}
138138

139-
fn extract_app_name_from_ipa(archive: &ZipArchive<Cursor<&[u8]>>) -> Result<String> {
139+
fn extract_app_name_from_ipa<'a>(archive: &'a ZipArchive<Cursor<&[u8]>>) -> Result<&'a str> {
140140
let pattern = Regex::new(r"^Payload/([^/]+)\.app/Info\.plist$")?;
141-
let mut matches = Vec::new();
142-
143-
for name in archive.file_names() {
144-
if let Some(captures) = pattern.captures(name) {
145-
matches.push(captures[1].to_string());
146-
}
147-
}
148-
149-
match matches.len() {
150-
1 => Ok(matches[0].clone()),
151-
_ => Err(anyhow!("IPA file did not contain exactly one .app.")),
141+
let matches = archive
142+
.file_names()
143+
.filter_map(|name| pattern.captures(name))
144+
.map(|c| c.get(1).expect("group 1 must be present").as_str())
145+
.take(2) // If there are ≥2 matches, we already know the IPA is invalid
146+
.collect::<Vec<_>>();
147+
148+
if let &[app_name] = matches.as_slice() {
149+
Ok(app_name)
150+
} else {
151+
Err(anyhow!("IPA did not contain exactly one .app."))
152152
}
153153
}

0 commit comments

Comments
 (0)