fix(launchpad): Ensure mobile artifact's zip structures are preserved#2585
fix(launchpad): Ensure mobile artifact's zip structures are preserved#2585NicoHinderling merged 7 commits intomasterfrom
Conversation
szokeasaurusrex
left a comment
There was a problem hiding this comment.
Please see inline comments.
Also, small nitpick: prior to merge, please rename the commit message to fix(mobile-app): ... in keeping with Sentry's commit message naming conventions (we use fix instead of bug, and mobile-app is the user-facing name of this feature).
c782961 to
6991773
Compare
szokeasaurusrex
left a comment
There was a problem hiding this comment.
Please see inline comments.
Also, I am struggling to see how the behavior has changed following these changes. As far as I can tell, this code should behave exactly the same as what we had before because it looks to me like the zip_path is equivalent to the previous relative_path.
Can you please explain what the desired difference in behavior is? If possible, please add a test case, which fails against the original code, but passes against the new code, to verify the desired behavior. This will also help me understand the purpose of this change, which I am currently struggling to grasp.
src/commands/mobile_app/upload.rs
Outdated
| .map(|entry| Ok(entry.into_path())) | ||
| .collect::<Result<Vec<_>>>()? | ||
| .into_iter() |
There was a problem hiding this comment.
Wrapping this in an Ok is unnecessary, because it is an infallible operation. Also, no need to collect into a vector just to make an iterator again.
| .map(|entry| Ok(entry.into_path())) | |
| .collect::<Result<Vec<_>>>()? | |
| .into_iter() | |
| .map(|entry| entry.into_path()) |
src/commands/mobile_app/upload.rs
Outdated
| debug!("Adding file to zip: {}", zip_path.display()); | ||
|
|
||
| zip.start_file(relative_path.to_string_lossy(), options)?; | ||
| zip.start_file(zip_path.to_string_lossy(), options)?; |
There was a problem hiding this comment.
How is this zip_path different from the relative_path we had before?
There was a problem hiding this comment.
The top level path is no longer being stripped.
Example: entry_path = /full/path/to/MyApp.xcarchive/Products/app.txt
relative_path stripped the entire path (/full/path/to/MyApp.xcarchive), losing the directory name
zip_path strips only the parent path (/full/path/to), keeping the directory name
Before: relative_path = Products/app.txt
After: zip_path = MyApp.xcarchive/Products/app.txt
There was a problem hiding this comment.
Okay! I think I see the difference now. Whereas previously, you called strip_prefix(path), you now call strip_prefix(path.parent), correct?
Assuming the above is correct, I have two questions:
- Couldn't you have simply added the path.parent call where we were previously computing the
relative_path? It seems like you are also refactoring the code by moving this changed strip_prefix into the for loop. Is this refactor causing some other functionality change which I am missing? - Is it reasonable to assume that the path should always have a parent? E.g., what if we are running this from the root directory? Not that I think it would be super common, but perhaps there are some scenarios where this could occur (e.g. if running from within a Docker container)?
There was a problem hiding this comment.
- No I think you're right that the for loop refactor was not necessary. I've changed it to be this way, apologies for the thrash.
- Yes it is but I've added a
ok_or_elsejust in case
It's about preserving the top directory in the path. I've added a unit test 👍 |
7a4cc1a to
b9d924c
Compare
szokeasaurusrex
left a comment
There was a problem hiding this comment.
Thanks for adding the test and explaining the functionality change, this makes some more sense now. Although, I still have a couple small questions
| Ok(()) | ||
| } | ||
|
|
||
| #[cfg(not(windows))] |
There was a problem hiding this comment.
Why not run on Windows?
There was a problem hiding this comment.
The unit test just fails because instead of MyApp.xcarchive/Products/app.txt it's something like C:\\MyApp.xcarchive\\Products\\app.txt. Lets just skip
src/commands/mobile_app/upload.rs
Outdated
| let mut archive = ZipArchive::new(zip_file)?; | ||
| let file = archive.by_index(0)?; | ||
| let file_path = file.name(); | ||
|
|
There was a problem hiding this comment.
not sure why the formatter did not catch this
src/commands/mobile_app/upload.rs
Outdated
| for entry_path in entries { | ||
| let zip_path = entry_path.strip_prefix( | ||
| path.parent().ok_or_else(|| anyhow!("Failed to get parent directory"))? | ||
| )?.to_owned(); |
There was a problem hiding this comment.
There's no need to call to_owned here; it just causes an unnecessary memory allocation and the code compiles without it.
| )?.to_owned(); | |
| )?; |
src/commands/mobile_app/upload.rs
Outdated
| debug!("Adding file to zip: {}", zip_path.display()); | ||
|
|
||
| zip.start_file(relative_path.to_string_lossy(), options)?; | ||
| zip.start_file(zip_path.to_string_lossy(), options)?; |
There was a problem hiding this comment.
Okay! I think I see the difference now. Whereas previously, you called strip_prefix(path), you now call strip_prefix(path.parent), correct?
Assuming the above is correct, I have two questions:
- Couldn't you have simply added the path.parent call where we were previously computing the
relative_path? It seems like you are also refactoring the code by moving this changed strip_prefix into the for loop. Is this refactor causing some other functionality change which I am missing? - Is it reasonable to assume that the path should always have a parent? E.g., what if we are running this from the root directory? Not that I think it would be super common, but perhaps there are some scenarios where this could occur (e.g. if running from within a Docker container)?
WIthout this, the code would remove the xcarchive wrapper directory, which causes issues when trying to parse the artifact in launchpad