Skip to content

Commit 71fbf3d

Browse files
committed
cleanup snap update service
1 parent 9069fdc commit 71fbf3d

3 files changed

Lines changed: 19 additions & 15 deletions

File tree

build/gulpfile.vscode.linux.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ function prepareSnapPackage(arch) {
204204
.pipe(rename('snap/snapcraft.yaml'));
205205

206206
const snapUpdate = gulp.src('resources/linux/snap/snapUpdate.sh', { base: '.' })
207-
.pipe(replace('@@NAME@@', product.applicationName))
208207
.pipe(rename(`usr/share/${product.applicationName}/snapUpdate.sh`));
209208

210209
const electronLaunch = gulp.src('resources/linux/snap/electron-launch', { base: '.' })

src/vs/code/electron-main/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ export class CodeApplication extends Disposable {
512512
services.set(IUpdateService, new SyncDescriptor(Win32UpdateService));
513513
} else if (process.platform === 'linux') {
514514
if (process.env.SNAP && process.env.SNAP_REVISION) {
515-
services.set(IUpdateService, new SyncDescriptor(SnapUpdateService));
515+
services.set(IUpdateService, new SyncDescriptor(SnapUpdateService, [process.env.SNAP, process.env.SNAP_REVISION]));
516516
} else {
517517
services.set(IUpdateService, new SyncDescriptor(LinuxUpdateService));
518518
}

src/vs/platform/update/electron-main/updateService.snap.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import * as path from 'path';
1414
import { realpath, watch } from 'fs';
1515
import { spawn } from 'child_process';
1616
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
17+
import { stat } from 'vs/base/node/pfs';
1718

1819
abstract 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

Comments
 (0)