Skip to content

Commit b8518fb

Browse files
committed
PR feedback
1 parent 8ff0a95 commit b8518fb

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

src/commands/mobile_app/upload.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,11 @@ fn validate_is_mobile_app(path: &Path, bytes: &[u8]) -> Result<()> {
208208

209209
// Check if the file is a zip file (then AAB, APK, or IPA)
210210
if is_zip_file(bytes) {
211+
#[cfg(target_os = "macos")]
211212
debug!("File is a zip, checking for AAB/APK/IPA format");
213+
#[cfg(not(target_os = "macos"))]
214+
debug!("File is a zip, checking for AAB/APK format");
215+
212216
if is_aab_file(bytes)? {
213217
debug!("Detected AAB file");
214218
return Ok(());

src/utils/mobile_app/apple.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use anyhow::{anyhow, Result};
22
use log::debug;
33
use regex::Regex;
4-
use std::path::{Path, PathBuf};
4+
use std::{
5+
path::{Path, PathBuf},
6+
sync::LazyLock,
7+
};
58

69
use crate::utils::fs::TempDir;
710
use apple_catalog_parsing;
@@ -83,7 +86,7 @@ pub fn ipa_to_xcarchive(ipa_path: &Path, ipa_bytes: &[u8], temp_dir: &TempDir) -
8386
let cursor = Cursor::new(ipa_bytes);
8487
let mut ipa_archive = ZipArchive::new(cursor)?;
8588

86-
let app_name = extract_app_name_from_ipa(&ipa_archive)?;
89+
let app_name = extract_app_name_from_ipa(&ipa_archive)?.to_owned();
8790

8891
// Extract all files from the archive
8992
for i in 0..ipa_archive.len() {
@@ -136,13 +139,15 @@ pub fn ipa_to_xcarchive(ipa_path: &Path, ipa_bytes: &[u8], temp_dir: &TempDir) -
136139
Ok(xcarchive_dir)
137140
}
138141

142+
static PATTERN: LazyLock<Regex> =
143+
LazyLock::new(|| Regex::new(r"^Payload/([^/]+)\.app/Info\.plist$").expect("regex is valid"));
144+
139145
fn extract_app_name_from_ipa<'a>(archive: &'a ZipArchive<Cursor<&[u8]>>) -> Result<&'a str> {
140-
let pattern = Regex::new(r"^Payload/([^/]+)\.app/Info\.plist$")?;
141146
let matches = archive
142147
.file_names()
143-
.filter_map(|name| pattern.captures(name))
148+
.filter_map(|name| PATTERN.captures(name))
144149
.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
150+
.take(2) // If there are ≥2 matches, we already know the IPA is invalid
146151
.collect::<Vec<_>>();
147152

148153
if let &[app_name] = matches.as_slice() {

src/utils/mobile_app/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
#[cfg(target_os = "macos")]
44
mod apple;
5-
#[cfg(target_os = "macos")]
6-
mod ipa;
75
mod validation;
86

97
#[cfg(target_os = "macos")]

tests/integration/mobile_app/upload.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{fs, str};
77
#[cfg(target_os = "macos")]
88
#[test]
99
fn command_mobile_app_upload_help() {
10-
TestManager::new().register_trycmd_test("mobile_app/mobile_app-upload-help.trycmd");
10+
TestManager::new().register_trycmd_test("mobile_app/mobile_app-upload-help-macos.trycmd");
1111
}
1212

1313
#[cfg(not(target_os = "macos"))]

0 commit comments

Comments
 (0)