@@ -14,6 +14,7 @@ import * as path from 'path';
1414import { realpath , watch } from 'fs' ;
1515import { spawn } from 'child_process' ;
1616import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry' ;
17+ import { stat } from 'vs/base/node/pfs' ;
1718
1819abstract class AbstractUpdateService2 implements IUpdateService {
1920
@@ -136,18 +137,21 @@ export class SnapUpdateService extends AbstractUpdateService2 {
136137
137138 _serviceBrand : any ;
138139
140+ private snapUpdatePath : string ;
141+
139142 constructor (
143+ private snap : string ,
144+ private snapRevision : string ,
140145 @ILifecycleService lifecycleService : ILifecycleService ,
141146 @IEnvironmentService environmentService : IEnvironmentService ,
142147 @ILogService logService : ILogService ,
143148 @ITelemetryService private telemetryService : ITelemetryService
144149 ) {
145150 super ( lifecycleService , environmentService , logService ) ;
146151
147- if ( typeof process . env . SNAP === 'undefined' ) {
148- throw new Error ( `'SNAP' environment variable not set` ) ;
149- }
150- const watcher = watch ( path . dirname ( process . env . SNAP ) ) ;
152+ this . snapUpdatePath = path . join ( this . snap , `usr/share/${ product . applicationName } /snapUpdate.sh` ) ;
153+
154+ const watcher = watch ( path . dirname ( this . snap ) ) ;
151155 const onChange = Event . fromNodeEventEmitter ( watcher , 'change' , ( _ , fileName : string ) => fileName ) ;
152156 const onCurrentChange = Event . filter ( onChange , n => n === 'current' ) ;
153157 const onDebouncedCurrentChange = Event . debounce ( onCurrentChange , ( _ , e ) => e , 2000 ) ;
@@ -192,21 +196,22 @@ export class SnapUpdateService extends AbstractUpdateService2 {
192196 this . logService . trace ( 'update#quitAndInstall(): running raw#quitAndInstall()' ) ;
193197
194198 // Allow 3 seconds for VS Code to close
195- spawn ( 'bash' , [ '-c' , path . join ( process . env . SNAP ! , `usr/share/ ${ product . applicationName } /snapUpdate.sh` ) ] , {
199+ spawn ( 'bash' , [ '-c' , this . snapUpdatePath ] , {
196200 detached : true ,
197201 stdio : [ 'ignore' , 'ignore' , 'ignore' ]
198202 } ) ;
199203 }
200204
201- private isUpdateAvailable ( ) : Promise < boolean > {
202- return new Promise ( ( c , e ) => {
203- realpath ( `${ path . dirname ( process . env . SNAP ! ) } /current` , ( err , resolvedCurrentSnapPath ) => {
204- if ( err ) { return e ( err ) ; }
205+ private async isUpdateAvailable ( ) : Promise < boolean > {
206+ try {
207+ await stat ( this . snapUpdatePath ) ;
208+ } catch ( err ) {
209+ return false ;
210+ }
205211
206- const currentRevision = path . basename ( resolvedCurrentSnapPath ) ;
207- c ( process . env . SNAP_REVISION !== currentRevision ) ;
208- } ) ;
209- } ) ;
212+ const resolvedCurrentSnapPath = await new Promise < string > ( ( c , e ) => realpath ( `${ path . dirname ( this . snap ) } /current` , ( err , r ) => err ? e ( err ) : c ( r ) ) ) ;
213+ const currentRevision = path . basename ( resolvedCurrentSnapPath ) ;
214+ return this . snapRevision !== currentRevision ;
210215 }
211216
212217 isLatestVersion ( ) : Promise < boolean | undefined > {
0 commit comments