Adding patch to rename backup file when it already exists (#22613) (#22614)

This commit is contained in:
Benjin Dubishar
2023-04-04 14:08:46 -07:00
committed by GitHub
parent 11304d9090
commit 56f8aa8b85

View File

@@ -10,6 +10,7 @@ import type * as azdataType from 'azdata';
import * as vscode from 'vscode';
import * as mssql from 'mssql';
import { promises as fs } from 'fs';
import { Uri, window } from 'vscode';
import { EntryType, IDatabaseReferenceProjectEntry, ISqlProject, ItemType } from 'sqldbproj';
import { DataSource } from './dataSources/dataSources';
@@ -445,6 +446,18 @@ export class Project implements ISqlProject {
TelemetryReporter.sendActionEvent(TelemetryViews.ProjectController, TelemetryActions.updateProjectForRoundtrip);
// due to bug in DacFx.Projects, if a backup file already exists this will fail
// workaround is to rename the existing backup
if (await utils.exists(this.projectFilePath + '_backup')) {
let counter = 2;
while (await utils.exists(this.projectFilePath + '_backup' + counter)) {
counter++;
}
await fs.rename(this.projectFilePath + '_backup', this.projectFilePath + '_backup' + counter);
}
const result = await this.sqlProjService.updateProjectForCrossPlatform(this.projectFilePath);
this.throwIfFailed(result);