Archived
1
0

Merge pull request #1486 from cdr/update-backup

Back up old directory when updating
This commit is contained in:
Asher 2020-04-02 17:28:27 -05:00 committed by GitHub
commit d2a31477c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 14 deletions

View File

@ -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..4f8543d975
--- /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';
@ -692,14 +692,10 @@ index 0000000000..96fbd4b0bb
+ headers: { "content-type": "application/json" },
+ });
+ if (response.status !== 200) {
+ throw new Error("Unexpected response");
+ throw new Error(response.statusText);
+ }
+
+ const json = await response.json();
+ if (!json.isLatest) {
+ throw new Error("Update failed");
+ }
+
+ (services.get(INotificationService) as INotificationService).info(`Updated to ${json.version}`);
+ };
+

View File

@ -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)

View File

@ -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 () => {