Back up code-server directory when updating
This commit is contained in:
parent
5fc00acc39
commit
d1445a8135
@ -221,8 +221,13 @@ export class UpdateHttpProvider extends HttpProvider {
|
|||||||
targetPath = path.resolve(__dirname, "../../../")
|
targetPath = path.resolve(__dirname, "../../../")
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("Replacing files", field("target", targetPath))
|
// Move the old directory to prevent potential data loss.
|
||||||
await fs.move(directoryPath, targetPath, { overwrite: true })
|
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)
|
await fs.remove(downloadPath)
|
||||||
|
|
||||||
|
@ -214,13 +214,18 @@ describe("update", () => {
|
|||||||
await p.downloadAndApplyUpdate(update, destination)
|
await p.downloadAndApplyUpdate(update, destination)
|
||||||
assert.equal(`console.log("UPDATED")`, await fs.readFile(entry, "utf8"))
|
assert.equal(`console.log("UPDATED")`, await fs.readFile(entry, "utf8"))
|
||||||
|
|
||||||
// Should still work if there is no existing version somehow.
|
// There should be a backup.
|
||||||
await fs.remove(destination)
|
const dir = (await fs.readdir(path.join(tmpdir, "tests/updates"))).filter((dir) => {
|
||||||
await p.downloadAndApplyUpdate(update, destination)
|
return dir.startsWith("code-server.")
|
||||||
assert.equal(`console.log("UPDATED")`, await fs.readFile(entry, "utf8"))
|
})
|
||||||
|
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)
|
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 () => {
|
it("should not reject if unable to fetch", async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user