From 5fc00acc3946359e530401e0ae349a60138178bf Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 2 Apr 2020 14:48:15 -0500 Subject: [PATCH 1/3] Fix incorrect reporting that an update failed --- ci/vscode.patch | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/ci/vscode.patch b/ci/vscode.patch index 5fecb159d..ede92a3e3 100644 --- a/ci/vscode.patch +++ b/ci/vscode.patch @@ -512,10 +512,10 @@ index eab8591492..26668701f7 100644 options.logService.error(`${logPrefix} socketFactory.connect() failed. Error:`); diff --git a/src/vs/server/browser/client.ts b/src/vs/server/browser/client.ts new file mode 100644 -index 0000000000..96fbd4b0bb +index 0000000000..a27a6f3a45 --- /dev/null +++ b/src/vs/server/browser/client.ts -@@ -0,0 +1,270 @@ +@@ -0,0 +1,266 @@ +import { Emitter } from 'vs/base/common/event'; +import { URI } from 'vs/base/common/uri'; +import { localize } from 'vs/nls'; @@ -696,10 +696,6 @@ index 0000000000..96fbd4b0bb + } + + const json = await response.json(); -+ if (!json.isLatest) { -+ throw new Error("Update failed"); -+ } -+ + (services.get(INotificationService) as INotificationService).info(`Updated to ${json.version}`); + }; + From d1445a8135d45fa46535e863e5de5e534fbcf759 Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 2 Apr 2020 16:21:32 -0500 Subject: [PATCH 2/3] Back up code-server directory when updating --- src/node/app/update.ts | 9 +++++++-- test/update.test.ts | 15 ++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/node/app/update.ts b/src/node/app/update.ts index 9ae64e5ce..7ee9f531b 100644 --- a/src/node/app/update.ts +++ b/src/node/app/update.ts @@ -221,8 +221,13 @@ export class UpdateHttpProvider extends HttpProvider { targetPath = path.resolve(__dirname, "../../../") } - logger.debug("Replacing files", field("target", targetPath)) - await fs.move(directoryPath, targetPath, { overwrite: true }) + // Move the old directory to prevent potential data loss. + const backupPath = path.resolve(targetPath, `../${path.basename(targetPath)}.${Date.now().toString()}`) + logger.debug("Replacing files", field("target", targetPath), field("backup", backupPath)) + await fs.move(targetPath, backupPath) + + // Move the new directory. + await fs.move(directoryPath, targetPath) await fs.remove(downloadPath) diff --git a/test/update.test.ts b/test/update.test.ts index da3634e92..18f0d9a6e 100644 --- a/test/update.test.ts +++ b/test/update.test.ts @@ -214,13 +214,18 @@ describe("update", () => { await p.downloadAndApplyUpdate(update, destination) assert.equal(`console.log("UPDATED")`, await fs.readFile(entry, "utf8")) - // Should still work if there is no existing version somehow. - await fs.remove(destination) - await p.downloadAndApplyUpdate(update, destination) - assert.equal(`console.log("UPDATED")`, await fs.readFile(entry, "utf8")) + // There should be a backup. + const dir = (await fs.readdir(path.join(tmpdir, "tests/updates"))).filter((dir) => { + return dir.startsWith("code-server.") + }) + assert.equal(dir.length, 1) + assert.equal( + `console.log("OLD")`, + await fs.readFile(path.join(tmpdir, "tests/updates", dir[0], "code-server"), "utf8"), + ) const archiveName = await p.getReleaseName(update) - assert.deepEqual(spy, ["/latest", `/download/${version}/${archiveName}`, `/download/${version}/${archiveName}`]) + assert.deepEqual(spy, ["/latest", `/download/${version}/${archiveName}`]) }) it("should not reject if unable to fetch", async () => { From 9c6581273ea1992bcfa929eddb3226fa411a21e6 Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 2 Apr 2020 17:20:25 -0500 Subject: [PATCH 3/3] Show proper error when an update fails --- ci/vscode.patch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/vscode.patch b/ci/vscode.patch index ede92a3e3..c89f05323 100644 --- a/ci/vscode.patch +++ b/ci/vscode.patch @@ -512,7 +512,7 @@ index eab8591492..26668701f7 100644 options.logService.error(`${logPrefix} socketFactory.connect() failed. Error:`); diff --git a/src/vs/server/browser/client.ts b/src/vs/server/browser/client.ts new file mode 100644 -index 0000000000..a27a6f3a45 +index 0000000000..4f8543d975 --- /dev/null +++ b/src/vs/server/browser/client.ts @@ -0,0 +1,266 @@ @@ -692,7 +692,7 @@ index 0000000000..a27a6f3a45 + headers: { "content-type": "application/json" }, + }); + if (response.status !== 200) { -+ throw new Error("Unexpected response"); ++ throw new Error(response.statusText); + } + + const json = await response.json();