Skip to content

Commit 6650034

Browse files
committed
Fix
1 parent 46ebd0f commit 6650034

File tree

2 files changed

+28
-91
lines changed

2 files changed

+28
-91
lines changed

src/commands/mobile_app/upload.rs

Lines changed: 26 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,10 @@ fn validate_is_mobile_app(path: &Path, bytes: &[u8]) -> Result<()> {
213213
}
214214

215215
fn ipa_to_xcarchive(ipa_path: &Path, ipa_bytes: &[u8]) -> Result<TempFile> {
216-
debug!("Converting IPA to XCArchive structure: {}", ipa_path.display());
216+
debug!(
217+
"Converting IPA to XCArchive structure: {}",
218+
ipa_path.display()
219+
);
217220

218221
let temp_dir = crate::utils::fs::TempDir::create()?;
219222
let xcarchive_dir = temp_dir.path().join("archive.xcarchive");
@@ -228,83 +231,37 @@ fn ipa_to_xcarchive(ipa_path: &Path, ipa_bytes: &[u8]) -> Result<TempFile> {
228231
let mut ipa_archive = zip::ZipArchive::new(cursor)?;
229232

230233
let mut app_name = String::new();
231-
let mut app_bundle_id = String::new();
232-
let mut app_version = String::new();
233-
let mut app_short_version = String::new();
234234

235235
// Extract .app from Payload/ directory
236236
for i in 0..ipa_archive.len() {
237237
let mut file = ipa_archive.by_index(i)?;
238-
let file_path = file.name();
239-
240-
if file_path.starts_with("Payload/") && file_path.ends_with(".app/") {
241-
// Extract app name from path like "Payload/MyApp.app/"
242-
let app_folder_name = file_path
243-
.strip_prefix("Payload/")
244-
.unwrap()
245-
.strip_suffix("/")
246-
.unwrap();
247-
app_name = app_folder_name.strip_suffix(".app").unwrap().to_string();
248-
debug!("Found app: {}", app_name);
249-
}
238+
let file_path = file.name().to_string();
250239

251-
if file_path.starts_with("Payload/") && !file.is_dir() {
252-
// Create the file path in the XCArchive structure
253-
let relative_path = file_path.strip_prefix("Payload/").unwrap();
254-
let target_path = applications_dir.join(relative_path);
255-
256-
// Create parent directories
257-
if let Some(parent) = target_path.parent() {
258-
std::fs::create_dir_all(parent)?;
240+
if let Some(stripped) = file_path.strip_prefix("Payload/") {
241+
if let Some(app_folder_name) = stripped.strip_suffix(".app/") {
242+
app_name = app_folder_name.to_string();
243+
debug!("Found app: {}", app_name);
259244
}
260245

261-
// Extract file
262-
let mut target_file = std::fs::File::create(&target_path)?;
263-
std::io::copy(&mut file, &mut target_file)?;
264-
265-
// If this is Info.plist, extract bundle information
266-
if relative_path.ends_with("/Info.plist") {
267-
debug!("Extracting bundle info from Info.plist");
268-
if let Ok(info_plist_data) = std::fs::read(&target_path) {
269-
if let Ok(plist) = plist::from_bytes::<plist::Dictionary>(&info_plist_data) {
270-
if let Some(bundle_id) = plist.get("CFBundleIdentifier")
271-
.and_then(|v| v.as_string()) {
272-
app_bundle_id = bundle_id.to_string();
273-
}
274-
if let Some(version) = plist.get("CFBundleVersion")
275-
.and_then(|v| v.as_string()) {
276-
app_version = version.to_string();
277-
}
278-
if let Some(short_version) = plist.get("CFBundleShortVersionString")
279-
.and_then(|v| v.as_string()) {
280-
app_short_version = short_version.to_string();
281-
}
282-
}
246+
if !file.is_dir() {
247+
// Create the file path in the XCArchive structure
248+
let target_path = applications_dir.join(stripped);
249+
250+
// Create parent directories
251+
if let Some(parent) = target_path.parent() {
252+
std::fs::create_dir_all(parent)?;
283253
}
254+
255+
// Extract file
256+
let mut target_file = std::fs::File::create(&target_path)?;
257+
std::io::copy(&mut file, &mut target_file)?;
284258
}
285259
}
286260
}
287261

288-
if app_name.is_empty() {
289-
app_name = "UnknownApp".to_string();
290-
}
291-
if app_bundle_id.is_empty() {
292-
app_bundle_id = "com.unknown.app".to_string();
293-
}
294-
if app_version.is_empty() {
295-
app_version = "1".to_string();
296-
}
297-
if app_short_version.is_empty() {
298-
app_short_version = "1.0".to_string();
299-
}
300-
301-
debug!("App info - Name: {}, Bundle ID: {}, Version: {}, Short Version: {}",
302-
app_name, app_bundle_id, app_version, app_short_version);
303-
304262
// Create Info.plist for XCArchive
305263
let info_plist_path = xcarchive_dir.join("Info.plist");
306-
let creation_date = chrono::Utc::now().format("%Y-%m-%dT%H:%M:%SZ").to_string();
307-
264+
308265
let info_plist_content = format!(
309266
r#"<?xml version="1.0" encoding="UTF-8"?>
310267
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
@@ -314,40 +271,20 @@ fn ipa_to_xcarchive(ipa_path: &Path, ipa_bytes: &[u8]) -> Result<TempFile> {
314271
<dict>
315272
<key>ApplicationPath</key>
316273
<string>Applications/{}.app</string>
317-
<key>Architectures</key>
318-
<array>
319-
<string>arm64</string>
320-
</array>
321-
<key>CFBundleIdentifier</key>
322-
<string>{}</string>
323-
<key>CFBundleShortVersionString</key>
324-
<string>{}</string>
325-
<key>CFBundleVersion</key>
326-
<string>{}</string>
327-
<key>SigningIdentity</key>
328-
<string>Apple Development: Converted from IPA</string>
329-
<key>Team</key>
330-
<string>CONVERTED</string>
331274
</dict>
332275
<key>ArchiveVersion</key>
333276
<integer>1</integer>
334-
<key>CreationDate</key>
335-
<date>{}</date>
336-
<key>Name</key>
337-
<string>{}</string>
338-
<key>SchemeName</key>
339-
<string>{}</string>
340277
</dict>
341278
</plist>"#,
342-
app_name, app_bundle_id, app_short_version, app_version, creation_date, app_name, app_name
279+
app_name
343280
);
344281

345282
std::fs::write(&info_plist_path, info_plist_content)?;
346283

347-
debug!("Created XCArchive Info.plist at: {}", info_plist_path.display());
348-
349-
// Now create a zip file containing the XCArchive
350-
debug!("Creating zip from XCArchive directory");
284+
debug!(
285+
"Created XCArchive Info.plist at: {}",
286+
info_plist_path.display()
287+
);
351288
normalize_directory(&xcarchive_dir)
352289
}
353290

src/utils/mobile_app/validation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ pub fn is_ipa_file(bytes: &[u8]) -> Result<bool> {
4848
for i in 0..archive.len() {
4949
let file = archive.by_index(i)?;
5050
let name = file.name();
51-
51+
5252
if name.starts_with("Payload/") {
5353
has_payload = true;
54-
54+
5555
// Check if there's a .app directory in Payload/
5656
if name.starts_with("Payload/") && name.ends_with(".app/") {
5757
has_app_in_payload = true;

0 commit comments

Comments
 (0)