diff --git a/build/gulpfile.vscode.linux.js b/build/gulpfile.vscode.linux.js index 67733f0e4b0..33972ba398b 100644 --- a/build/gulpfile.vscode.linux.js +++ b/build/gulpfile.vscode.linux.js @@ -204,7 +204,6 @@ function prepareSnapPackage(arch) { .pipe(rename('snap/snapcraft.yaml')); const snapUpdate = gulp.src('resources/linux/snap/snapUpdate.sh', { base: '.' }) - .pipe(replace('@@NAME@@', product.applicationName)) .pipe(rename(`usr/share/${product.applicationName}/snapUpdate.sh`)); const electronLaunch = gulp.src('resources/linux/snap/electron-launch', { base: '.' }) diff --git a/src/vs/code/electron-main/app.ts b/src/vs/code/electron-main/app.ts index 582880dfe10..fec679e0282 100644 --- a/src/vs/code/electron-main/app.ts +++ b/src/vs/code/electron-main/app.ts @@ -512,7 +512,7 @@ export class CodeApplication extends Disposable { services.set(IUpdateService, new SyncDescriptor(Win32UpdateService)); } else if (process.platform === 'linux') { if (process.env.SNAP && process.env.SNAP_REVISION) { - services.set(IUpdateService, new SyncDescriptor(SnapUpdateService)); + services.set(IUpdateService, new SyncDescriptor(SnapUpdateService, [process.env.SNAP, process.env.SNAP_REVISION])); } else { services.set(IUpdateService, new SyncDescriptor(LinuxUpdateService)); } diff --git a/src/vs/platform/update/electron-main/updateService.snap.ts b/src/vs/platform/update/electron-main/updateService.snap.ts index 99a1a9c0083..c11676fed4b 100644 --- a/src/vs/platform/update/electron-main/updateService.snap.ts +++ b/src/vs/platform/update/electron-main/updateService.snap.ts @@ -14,6 +14,7 @@ import * as path from 'path'; import { realpath, watch } from 'fs'; import { spawn } from 'child_process'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; +import { stat } from 'vs/base/node/pfs'; abstract class AbstractUpdateService2 implements IUpdateService { @@ -136,7 +137,11 @@ export class SnapUpdateService extends AbstractUpdateService2 { _serviceBrand: any; + private snapUpdatePath: string; + constructor( + private snap: string, + private snapRevision: string, @ILifecycleService lifecycleService: ILifecycleService, @IEnvironmentService environmentService: IEnvironmentService, @ILogService logService: ILogService, @@ -144,10 +149,9 @@ export class SnapUpdateService extends AbstractUpdateService2 { ) { super(lifecycleService, environmentService, logService); - if (typeof process.env.SNAP === 'undefined') { - throw new Error(`'SNAP' environment variable not set`); - } - const watcher = watch(path.dirname(process.env.SNAP)); + this.snapUpdatePath = path.join(this.snap, `usr/share/${product.applicationName}/snapUpdate.sh`); + + const watcher = watch(path.dirname(this.snap)); const onChange = Event.fromNodeEventEmitter(watcher, 'change', (_, fileName: string) => fileName); const onCurrentChange = Event.filter(onChange, n => n === 'current'); const onDebouncedCurrentChange = Event.debounce(onCurrentChange, (_, e) => e, 2000); @@ -192,21 +196,22 @@ export class SnapUpdateService extends AbstractUpdateService2 { this.logService.trace('update#quitAndInstall(): running raw#quitAndInstall()'); // Allow 3 seconds for VS Code to close - spawn('bash', ['-c', path.join(process.env.SNAP!, `usr/share/${product.applicationName}/snapUpdate.sh`)], { + spawn('bash', ['-c', this.snapUpdatePath], { detached: true, stdio: ['ignore', 'ignore', 'ignore'] }); } - private isUpdateAvailable(): Promise { - return new Promise((c, e) => { - realpath(`${path.dirname(process.env.SNAP!)}/current`, (err, resolvedCurrentSnapPath) => { - if (err) { return e(err); } + private async isUpdateAvailable(): Promise { + try { + await stat(this.snapUpdatePath); + } catch (err) { + return false; + } - const currentRevision = path.basename(resolvedCurrentSnapPath); - c(process.env.SNAP_REVISION !== currentRevision); - }); - }); + const resolvedCurrentSnapPath = await new Promise((c, e) => realpath(`${path.dirname(this.snap)}/current`, (err, r) => err ? e(err) : c(r))); + const currentRevision = path.basename(resolvedCurrentSnapPath); + return this.snapRevision !== currentRevision; } isLatestVersion(): Promise {