Archived
1
0

Back up code-server directory when updating

This commit is contained in:
Asher
2020-04-02 16:21:32 -05:00
parent 5fc00acc39
commit d1445a8135
2 changed files with 17 additions and 7 deletions

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)