@@ -27,7 +27,6 @@ import {
27
27
streamToBuffer ,
28
28
systemDefaultPlatform ,
29
29
} from './util' ;
30
- import * as timers from 'timers/promises' ;
31
30
32
31
const extensionRoot = process . cwd ( ) ;
33
32
const pipelineAsync = promisify ( pipeline ) ;
@@ -332,6 +331,8 @@ function spawnDecompressorChild(command: string, args: ReadonlyArray<string>, in
332
331
333
332
export const defaultCachePath = path . resolve ( extensionRoot , '.vscode-test' ) ;
334
333
334
+ const COMPLETE_FILE_NAME = 'is-complete' ;
335
+
335
336
/**
336
337
* Download and unzip a copy of VS Code.
337
338
* @returns Promise of `vscodeExecutablePath`.
@@ -368,7 +369,7 @@ export async function download(options: Partial<DownloadOptions> = {}): Promise<
368
369
reporter . report ( { stage : ProgressReportStage . ResolvedVersion , version } ) ;
369
370
370
371
const downloadedPath = path . resolve ( cachePath , makeDownloadDirName ( platform , version ) ) ;
371
- if ( fs . existsSync ( downloadedPath ) ) {
372
+ if ( fs . existsSync ( path . join ( downloadedPath , COMPLETE_FILE_NAME ) ) ) {
372
373
if ( isInsiderVersionIdentifier ( version ) ) {
373
374
reporter . report ( { stage : ProgressReportStage . FetchingInsidersMetadata } ) ;
374
375
const { version : currentHash , date : currentDate } = insidersDownloadDirMetadata ( downloadedPath , platform ) ;
@@ -408,10 +409,7 @@ export async function download(options: Partial<DownloadOptions> = {}): Promise<
408
409
409
410
for ( let i = 0 ; ; i ++ ) {
410
411
try {
411
- // Use a staging directory and rename after unzipping so partially-
412
- // downloaded/unzipped files aren't "stuck" being used.
413
- const downloadStaging = `${ downloadedPath } .tmp` ;
414
- await fs . promises . rm ( downloadStaging , { recursive : true , force : true } ) ;
412
+ await fs . promises . rm ( downloadedPath , { recursive : true , force : true } ) ;
415
413
416
414
const { stream, format } = await downloadVSCodeArchive ( {
417
415
version,
@@ -422,22 +420,9 @@ export async function download(options: Partial<DownloadOptions> = {}): Promise<
422
420
} ) ;
423
421
// important! do not put anything async here, since unzipVSCode will need
424
422
// to start consuming the stream immediately.
425
- await unzipVSCode ( reporter , downloadStaging , stream , platform , format ) ;
426
-
427
- // Windows file handles can get released asynchronously, give it a few retries:
428
- for ( let attempts = 20 ; attempts >= 0 ; attempts -- ) {
429
- try {
430
- await fs . promises . rename ( downloadStaging , downloadedPath ) ;
431
- break ;
432
- } catch ( e ) {
433
- if ( attempts === 0 ) {
434
- throw e ;
435
- } else {
436
- await timers . setTimeout ( 200 ) ;
437
- }
438
- }
439
- }
423
+ await unzipVSCode ( reporter , downloadedPath , stream , platform , format ) ;
440
424
425
+ await fs . promises . writeFile ( path . join ( downloadedPath , COMPLETE_FILE_NAME ) , '' ) ;
441
426
reporter . report ( { stage : ProgressReportStage . NewInstallComplete , downloadedPath } ) ;
442
427
break ;
443
428
} catch ( error ) {
0 commit comments