Skip to content

Commit d5d4033

Browse files
committedApr 23, 2024
Check for matching installations before downloading
1 parent 2afa7e2 commit d5d4033

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed
 

‎src/main/kotlin/com/coder/gateway/CoderRemoteConnectionHandle.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class CoderRemoteConnectionHandle {
100100
// out into a new dialog.
101101
ApplicationManager.getApplication().invokeAndWait {
102102
Messages.showMessageDialog(
103-
e.message ?: e.javaClass.simpleName,
103+
e.message ?: e.javaClass.simpleName ?: "Aborted",
104104
CoderGatewayBundle.message("gateway.connector.coder.connection.failed"),
105105
Messages.getErrorIcon())
106106
}

‎src/main/kotlin/com/coder/gateway/models/WorkspaceProjectIDE.kt

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,29 +83,7 @@ class WorkspaceProjectIDE(
8383
true
8484
)
8585

86-
// Ensure the IDE exists. If not, download it if we have a download
87-
// URL. We do this ourselves instead of just giving JetBrains the
88-
// download source or path and letting them handle it:
89-
// 1. To get the actual directory into which the IDE is extracted (the
90-
// postDeployCallback does not give us this information). We want
91-
// this directory to run a setup script inside it.
92-
// 2. To provide a better error message when the IDE is gone (JetBrains
93-
// by default will just hang trying to connect to it).
94-
// 3. So if the IDE was deleted, we can download it again assuming we
95-
// stored the original download URL.
96-
val path: String
97-
if (idePathOnHost.isNullOrBlank()) {
98-
logger.info("No install found for $ideName on $hostname")
99-
path = this.doDeploy(accessor, indicator, timeout)
100-
} else {
101-
indicator.text = "Verifying remote IDE exists..."
102-
logger.info("Verifying $ideName exists at $idePathOnHost on $hostname")
103-
val validatedPath = validateIDEInstallPath(idePathOnHost, accessor).pathOrNull
104-
path = if (validatedPath != null) {
105-
logger.info("$ideName already exists at ${validatedPath.toRawString()} on $hostname")
106-
validatedPath.toRawString()
107-
} else this.doDeploy(accessor, indicator, timeout)
108-
}
86+
val path = this.doDeploy(accessor, indicator, timeout)
10987
idePathOnHost = path
11088

11189
if (setupCommand.isNotBlank()) {
@@ -148,13 +126,38 @@ class WorkspaceProjectIDE(
148126
}
149127

150128
/**
151-
* Deploy the IDE and return the path to its location on disk.
129+
* Deploy the IDE if necessary and return the path to its location on disk.
152130
*/
153131
private suspend fun doDeploy(accessor: HighLevelHostAccessor, indicator: ProgressIndicator, timeout: Duration): String {
132+
// The backend might already exist at the provided path.
133+
if (!idePathOnHost.isNullOrBlank()) {
134+
indicator.text = "Verifying $ideName installation..."
135+
logger.info("Verifying $ideName exists at $idePathOnHost on $hostname")
136+
val validatedPath = validateIDEInstallPath(idePathOnHost, accessor).pathOrNull
137+
if (validatedPath != null) {
138+
logger.info("$ideName exists at ${validatedPath.toRawString()} on $hostname")
139+
return validatedPath.toRawString()
140+
}
141+
}
142+
143+
// The backend might already be installed somewhere on the system.
144+
indicator.text = "Searching for $ideName installation..."
145+
logger.info("Searching for $ideName on $hostname")
146+
val installed = accessor.getInstalledIDEs().find {
147+
it.product == ideProductCode && it.buildNumber == ideBuildNumber }
148+
if (installed != null) {
149+
logger.info("$ideName found at ${installed.pathToIde} on $hostname")
150+
return installed.pathToIde
151+
}
152+
153+
// Otherwise we have to download it.
154154
if (downloadSource.isNullOrBlank()) {
155155
throw Exception("The IDE could not be found on the remote and no download source was provided")
156156
}
157157

158+
// TODO: Should we download to idePathOnHost if set? That would require
159+
// symlinking instead of creating the sentinel file if the path is
160+
// outside the default dist directory.
158161
val distDir = accessor.getDefaultDistDir()
159162

160163
// HighLevelHostAccessor.downloadFile does NOT create the directory.

0 commit comments

Comments
 (0)
Please sign in to comment.