@@ -14,7 +14,7 @@ const MAX_URLS = 10;
14
14
15
15
export class Storage {
16
16
constructor (
17
- private readonly output : vscode . OutputChannel ,
17
+ private readonly output : vscode . LogOutputChannel ,
18
18
private readonly memento : vscode . Memento ,
19
19
private readonly secrets : vscode . SecretStorage ,
20
20
private readonly globalStorageUri : vscode . Uri ,
@@ -129,55 +129,52 @@ export class Storage {
129
129
const enableDownloads =
130
130
vscode . workspace . getConfiguration ( ) . get ( "coder.enableDownloads" ) !==
131
131
false ;
132
- this . output . appendLine (
132
+ this . output . info (
133
133
`Downloads are ${ enableDownloads ? "enabled" : "disabled" } ` ,
134
134
) ;
135
135
136
136
// Get the build info to compare with the existing binary version, if any,
137
137
// and to log for debugging.
138
138
const buildInfo = await restClient . getBuildInfo ( ) ;
139
- this . output . appendLine ( `Got server version: ${ buildInfo . version } ` ) ;
139
+ this . output . info ( `Got server version: ${ buildInfo . version } ` ) ;
140
140
141
141
// Check if there is an existing binary and whether it looks valid. If it
142
142
// is valid and matches the server, or if it does not match the server but
143
143
// downloads are disabled, we can return early.
144
144
const binPath = path . join ( this . getBinaryCachePath ( label ) , cli . name ( ) ) ;
145
- this . output . appendLine ( `Using binary path: ${ binPath } ` ) ;
145
+ this . output . info ( `Using binary path: ${ binPath } ` ) ;
146
146
const stat = await cli . stat ( binPath ) ;
147
147
if ( stat === undefined ) {
148
- this . output . appendLine ( "No existing binary found, starting download" ) ;
148
+ this . output . info ( "No existing binary found, starting download" ) ;
149
149
} else {
150
- this . output . appendLine (
151
- `Existing binary size is ${ prettyBytes ( stat . size ) } ` ,
152
- ) ;
150
+ this . output . info ( `Existing binary size is ${ prettyBytes ( stat . size ) } ` ) ;
153
151
try {
154
152
const version = await cli . version ( binPath ) ;
155
- this . output . appendLine ( `Existing binary version is ${ version } ` ) ;
153
+ this . output . info ( `Existing binary version is ${ version } ` ) ;
156
154
// If we have the right version we can avoid the request entirely.
157
155
if ( version === buildInfo . version ) {
158
- this . output . appendLine (
156
+ this . output . info (
159
157
"Using existing binary since it matches the server version" ,
160
158
) ;
161
159
return binPath ;
162
160
} else if ( ! enableDownloads ) {
163
- this . output . appendLine (
161
+ this . output . info (
164
162
"Using existing binary even though it does not match the server version because downloads are disabled" ,
165
163
) ;
166
164
return binPath ;
167
165
}
168
- this . output . appendLine (
166
+ this . output . info (
169
167
"Downloading since existing binary does not match the server version" ,
170
168
) ;
171
169
} catch ( error ) {
172
- this . output . appendLine (
173
- `Unable to get version of existing binary: ${ error } ` ,
170
+ this . output . error (
171
+ `Unable to get version of existing binary: ${ error } . Downloading new binary instead ` ,
174
172
) ;
175
- this . output . appendLine ( "Downloading new binary instead" ) ;
176
173
}
177
174
}
178
175
179
176
if ( ! enableDownloads ) {
180
- this . output . appendLine (
177
+ this . output . error (
181
178
"Unable to download CLI because downloads are disabled" ,
182
179
) ;
183
180
throw new Error ( "Unable to download CLI because downloads are disabled" ) ;
@@ -187,9 +184,9 @@ export class Storage {
187
184
const removed = await cli . rmOld ( binPath ) ;
188
185
removed . forEach ( ( { fileName, error } ) => {
189
186
if ( error ) {
190
- this . output . appendLine ( `Failed to remove ${ fileName } : ${ error } ` ) ;
187
+ this . output . error ( `Failed to remove ${ fileName } : ${ error } ` ) ;
191
188
} else {
192
- this . output . appendLine ( `Removed ${ fileName } ` ) ;
189
+ this . output . info ( `Removed ${ fileName } ` ) ;
193
190
}
194
191
} ) ;
195
192
@@ -202,12 +199,12 @@ export class Storage {
202
199
configSource && String ( configSource ) . trim ( ) . length > 0
203
200
? String ( configSource )
204
201
: "/bin/" + binName ;
205
- this . output . appendLine ( `Downloading binary from: ${ binSource } ` ) ;
202
+ this . output . info ( `Downloading binary from: ${ binSource } ` ) ;
206
203
207
204
// Ideally we already caught that this was the right version and returned
208
205
// early, but just in case set the ETag.
209
206
const etag = stat !== undefined ? await cli . eTag ( binPath ) : "" ;
210
- this . output . appendLine ( `Using ETag: ${ etag } ` ) ;
207
+ this . output . info ( `Using ETag: ${ etag } ` ) ;
211
208
212
209
// Make the download request.
213
210
const controller = new AbortController ( ) ;
@@ -223,20 +220,18 @@ export class Storage {
223
220
// Ignore all errors so we can catch a 404!
224
221
validateStatus : ( ) => true ,
225
222
} ) ;
226
- this . output . appendLine ( `Got status code ${ resp . status } ` ) ;
223
+ this . output . info ( `Got status code ${ resp . status } ` ) ;
227
224
228
225
switch ( resp . status ) {
229
226
case 200 : {
230
227
const rawContentLength = resp . headers [ "content-length" ] ;
231
228
const contentLength = Number . parseInt ( rawContentLength ) ;
232
229
if ( Number . isNaN ( contentLength ) ) {
233
- this . output . appendLine (
230
+ this . output . error (
234
231
`Got invalid or missing content length: ${ rawContentLength } ` ,
235
232
) ;
236
233
} else {
237
- this . output . appendLine (
238
- `Got content length: ${ prettyBytes ( contentLength ) } ` ,
239
- ) ;
234
+ this . output . info ( `Got content length: ${ prettyBytes ( contentLength ) } ` ) ;
240
235
}
241
236
242
237
// Download to a temporary file.
@@ -317,11 +312,11 @@ export class Storage {
317
312
// False means the user canceled, although in practice it appears we
318
313
// would not get this far because VS Code already throws on cancelation.
319
314
if ( ! completed ) {
320
- this . output . appendLine ( "User aborted download" ) ;
315
+ this . output . error ( "User aborted download" ) ;
321
316
throw new Error ( "User aborted download" ) ;
322
317
}
323
318
324
- this . output . appendLine (
319
+ this . output . info (
325
320
`Downloaded ${ prettyBytes ( written ) } to ${ path . basename ( tempFile ) } ` ,
326
321
) ;
327
322
@@ -331,35 +326,31 @@ export class Storage {
331
326
if ( stat !== undefined ) {
332
327
const oldBinPath =
333
328
binPath + ".old-" + Math . random ( ) . toString ( 36 ) . substring ( 8 ) ;
334
- this . output . appendLine (
329
+ this . output . info (
335
330
`Moving existing binary to ${ path . basename ( oldBinPath ) } ` ,
336
331
) ;
337
332
await fs . rename ( binPath , oldBinPath ) ;
338
333
}
339
334
340
335
// Then move the temporary binary into the right place.
341
- this . output . appendLine (
342
- `Moving downloaded file to ${ path . basename ( binPath ) } ` ,
343
- ) ;
336
+ this . output . info ( `Moving downloaded file to ${ path . basename ( binPath ) } ` ) ;
344
337
await fs . mkdir ( path . dirname ( binPath ) , { recursive : true } ) ;
345
338
await fs . rename ( tempFile , binPath ) ;
346
339
347
340
// For debugging, to see if the binary only partially downloaded.
348
341
const newStat = await cli . stat ( binPath ) ;
349
- this . output . appendLine (
342
+ this . output . info (
350
343
`Downloaded binary size is ${ prettyBytes ( newStat ?. size || 0 ) } ` ,
351
344
) ;
352
345
353
346
// Make sure we can execute this new binary.
354
347
const version = await cli . version ( binPath ) ;
355
- this . output . appendLine ( `Downloaded binary version is ${ version } ` ) ;
348
+ this . output . info ( `Downloaded binary version is ${ version } ` ) ;
356
349
357
350
return binPath ;
358
351
}
359
352
case 304 : {
360
- this . output . appendLine (
361
- "Using existing binary since server returned a 304" ,
362
- ) ;
353
+ this . output . info ( "Using existing binary since server returned a 304" ) ;
363
354
return binPath ;
364
355
}
365
356
case 404 : {
@@ -508,7 +499,7 @@ export class Storage {
508
499
}
509
500
510
501
public writeToCoderOutputChannel ( message : string ) {
511
- this . output . appendLine ( `[ ${ new Date ( ) . toISOString ( ) } ] ${ message } ` ) ;
502
+ this . output . info ( message ) ;
512
503
// We don't want to focus on the output here, because the
513
504
// Coder server is designed to restart gracefully for users
514
505
// because of P2P connections, and we don't want to draw
0 commit comments