Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 54
ADFA-2446 | Improve terminal bootstrap install resilience and user messaging#812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
8 changes: 5 additions & 3 deletions
8 app/src/main/java/com/itsaky/androidide/assets/AssetsInstallationHelper.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 35 additions & 16 deletions
51 app/src/main/java/com/itsaky/androidide/assets/BundledAssetsInstaller.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 27 additions & 14 deletions
41 app/src/main/java/com/itsaky/androidide/assets/SplitAssetsInstaller.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -6,6 +6,8 @@ import com.itsaky.androidide.app.configuration.CpuArch | ||
| import com.itsaky.androidide.resources.R | ||
| import com.itsaky.androidide.utils.Environment | ||
| import com.itsaky.androidide.utils.TerminalInstaller | ||
| import com.itsaky.androidide.utils.retryOnceOnNoSuchFile | ||
| import com.itsaky.androidide.utils.withTempZipChannel | ||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.withContext | ||
| import org.adfa.constants.ANDROID_SDK_ZIP | ||
| @@ -66,22 +68,33 @@ data object SplitAssetsInstaller : BaseAssetsInstaller() { | ||
| AssetsInstallationHelper.BOOTSTRAP_ENTRY_NAME -> { | ||
| logger.debug("Extracting 'bootstrap.zip' to dir: {}", stagingDir) | ||
| // We need a SeekableByteChannel for the TerminalInstaller, but the ZipInputStream is not seekable. | ||
| // The only way is to write it to a temporary file first. | ||
| val tempBootstrap = Files.createTempFile(stagingDir, "bootstrap", ".zip") | ||
| try { | ||
| Files.newOutputStream(tempBootstrap).use { out -> | ||
| zipInput.copyTo(out) | ||
| val result = retryOnceOnNoSuchFile( | ||
| onFirstFailure = { Files.createDirectories(stagingDir) }, | ||
| onSecondFailure = { e2 -> | ||
| logger.error("Failed to open temporary bootstrap zip after retry", e2) | ||
| return@withContext | ||
| } | ||
| val channel = Files.newByteChannel(tempBootstrap) | ||
| val result = TerminalInstaller.installIfNeeded(context, channel) | ||
| if (result !is TerminalInstaller.InstallResult.Success) { | ||
| // Log the error and continue with other assets. | ||
| logger.error("Failed to install terminal: $result") | ||
| } | ||
| } finally { | ||
| Files.deleteIfExists(tempBootstrap) | ||
| ) { | ||
| withTempZipChannel( | ||
| stagingDir = stagingDir, | ||
| prefix = "bootstrap", | ||
| writeTo = { path -> | ||
| zipFile.getInputStream(entry).use { freshZipInput -> | ||
| Files.newOutputStream(path).use { out -> | ||
| freshZipInput.copyTo(out) | ||
| } | ||
| } | ||
| }, | ||
| useChannel = { ch -> | ||
| TerminalInstaller.installIfNeeded(context, ch) | ||
| } | ||
| ) | ||
| } | ||
| if (result !is TerminalInstaller.InstallResult.Success) { | ||
| logger.error("Failed to install terminal: {}", result) | ||
| } | ||
jatezzz marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| logger.debug("Completed extracting 'bootstrap.zip' to dir: {}", stagingDir) | ||
| } | ||
56 changes: 56 additions & 0 deletions
56 app/src/main/java/com/itsaky/androidide/utils/InstallerIoUtils.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package com.itsaky.androidide.utils | ||
| import android.content.Context | ||
| import com.aayushatharva.brotli4j.decoder.BrotliInputStream | ||
| import java.nio.channels.SeekableByteChannel | ||
| import java.nio.file.Files | ||
| import java.nio.file.NoSuchFileException | ||
| import java.nio.file.Path | ||
| internal inline fun <T> withTempZipChannel( | ||
| stagingDir: Path, | ||
| prefix: String, | ||
| writeTo: (Path) -> Unit, | ||
| useChannel: (SeekableByteChannel) -> T, | ||
| ): T { | ||
| val tempZipPath = Files.createTempFile(stagingDir, prefix, ".zip") | ||
| try { | ||
| writeTo(tempZipPath) | ||
| Files.newByteChannel(tempZipPath).use { ch -> | ||
| return useChannel(ch) | ||
| } | ||
| } finally { | ||
| Files.deleteIfExists(tempZipPath) | ||
| } | ||
| } | ||
| internal fun writeBrotliAssetToPath( | ||
| context: Context, | ||
| assetPath: String, | ||
| destPath: Path, | ||
| ) { | ||
| context.assets.open(assetPath).use { assetStream -> | ||
| BrotliInputStream(assetStream).use { brotli -> | ||
| Files.newOutputStream(destPath).use { output -> | ||
| brotli.copyTo(output) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| internal inline fun <T> retryOnceOnNoSuchFile( | ||
| onFirstFailure: () -> Unit = {}, | ||
| onSecondFailure: (NoSuchFileException) -> Nothing, | ||
| block: () -> T, | ||
| ): T { | ||
| return try { | ||
| block() | ||
| } catch (_: NoSuchFileException) { | ||
| onFirstFailure() | ||
| try { | ||
| block() | ||
| } catch (e2: NoSuchFileException) { | ||
| onSecondFailure(e2) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.