Skip to content

Commit

Permalink
[cli] Fix download-build returning cached corrupted APKs (#186)
Browse files Browse the repository at this point in the history
* [cli] Fix download-build returning cached corrupted APKs

* Add changelog entry
  • Loading branch information
gabrieldonadel authored Mar 1, 2024
1 parent f7fa84f commit c9a1732
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

### 🐛 Bug fixes

- Prevent CLI from returning invalid cached APKs when the download of the build fails. ([#156](https://github.com/expo/orbit/pull/156) by [@gabrieldonadel](https://github.com/gabrieldonadel))

### 💡 Others

- Fix typo in error alert message. ([#183](https://github.com/expo/orbit/pull/183) by [@prettyClouds](https://github.com/prettyClouds))
Expand Down
12 changes: 7 additions & 5 deletions packages/eas-shared/src/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,21 @@ export async function downloadAndMaybeExtractAppAsync(url: string): Promise<stri

await fs.promises.mkdir(outputDir, { recursive: true });

const tmpArchivePathDir = path.join(getTmpDirectory(), uuidv4());
await fs.mkdir(tmpArchivePathDir, { recursive: true });
if (url.endsWith('apk')) {
const apkFilePath = path.join(outputDir, `${uuidv4()}.apk`);
const tmpApkFilePath = path.join(tmpArchivePathDir, `${uuidv4()}.tar.gz`);
await downloadFileWithProgressTrackerAsync(
url,
apkFilePath,
tmpApkFilePath,
(ratio, total) => `Downloading app (${formatBytes(total * ratio)} / ${formatBytes(total)})`,
'Successfully downloaded app'
);
// Only move the file to correct location after the download is complete to avoid corrupted files
const apkFilePath = path.join(outputDir, `${uuidv4()}.apk`);
await fs.move(tmpApkFilePath, apkFilePath);
return apkFilePath;
} else {
const tmpArchivePathDir = path.join(getTmpDirectory(), uuidv4());
await fs.mkdir(tmpArchivePathDir, { recursive: true });

const tmpArchivePath = path.join(tmpArchivePathDir, `${uuidv4()}.tar.gz`);

await downloadFileWithProgressTrackerAsync(
Expand Down

0 comments on commit c9a1732

Please sign in to comment.