Skip to content

Commit c4fb721

Browse files
committed
Fix
1 parent 46ebd0f commit c4fb721

File tree

2 files changed

+19
-88
lines changed

2 files changed

+19
-88
lines changed

src/commands/mobile_app/upload.rs

Lines changed: 17 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -228,82 +228,36 @@ fn ipa_to_xcarchive(ipa_path: &Path, ipa_bytes: &[u8]) -> Result<TempFile> {
228228
let mut ipa_archive = zip::ZipArchive::new(cursor)?;
229229

230230
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();
234231

235232
// Extract .app from Payload/ directory
236233
for i in 0..ipa_archive.len() {
237234
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-
}
250-
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);
235+
let file_path = file.name().to_string();
255236

256-
// Create parent directories
257-
if let Some(parent) = target_path.parent() {
258-
std::fs::create_dir_all(parent)?;
237+
if let Some(stripped) = file_path.strip_prefix("Payload/") {
238+
if let Some(app_folder_name) = stripped.strip_suffix(".app/") {
239+
app_name = app_folder_name.to_string();
240+
debug!("Found app: {}", app_name);
259241
}
260242

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-
}
243+
if !file.is_dir() {
244+
// Create the file path in the XCArchive structure
245+
let target_path = applications_dir.join(stripped);
246+
247+
// Create parent directories
248+
if let Some(parent) = target_path.parent() {
249+
std::fs::create_dir_all(parent)?;
283250
}
251+
252+
// Extract file
253+
let mut target_file = std::fs::File::create(&target_path)?;
254+
std::io::copy(&mut file, &mut target_file)?;
284255
}
285256
}
286257
}
287258

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-
304259
// Create Info.plist for XCArchive
305260
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();
307261

308262
let info_plist_content = format!(
309263
r#"<?xml version="1.0" encoding="UTF-8"?>
@@ -314,40 +268,17 @@ fn ipa_to_xcarchive(ipa_path: &Path, ipa_bytes: &[u8]) -> Result<TempFile> {
314268
<dict>
315269
<key>ApplicationPath</key>
316270
<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>
331271
</dict>
332272
<key>ArchiveVersion</key>
333273
<integer>1</integer>
334-
<key>CreationDate</key>
335-
<date>{}</date>
336-
<key>Name</key>
337-
<string>{}</string>
338-
<key>SchemeName</key>
339-
<string>{}</string>
340274
</dict>
341275
</plist>"#,
342-
app_name, app_bundle_id, app_short_version, app_version, creation_date, app_name, app_name
276+
app_name
343277
);
344278

345279
std::fs::write(&info_plist_path, info_plist_content)?;
346280

347281
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");
351282
normalize_directory(&xcarchive_dir)
352283
}
353284

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)