Don't allow duplicate file/folder entries to be added to sql projects (#15104)

* don't allow adding the same file or folder to the sqlproj if it has already been added

* add a couple more checks in test

* toLowerCase when comparing
This commit is contained in:
Kim Santiago
2021-04-13 16:08:43 -07:00
committed by GitHub
parent 0ce57eb9b3
commit b7ea1c1bf3
3 changed files with 34 additions and 1 deletions

View File

@@ -266,6 +266,11 @@ export class Project {
public async addFolderItem(relativeFolderPath: string): Promise<FileProjectEntry> {
const absoluteFolderPath = path.join(this.projectFolderPath, relativeFolderPath);
// check if folder already has been added to sqlproj
if (this.files.find(f => f.relativePath.toLowerCase() === relativeFolderPath.toLowerCase())) {
throw new Error(constants.folderAlreadyAddedToProject((relativeFolderPath)));
}
//If folder doesn't exist, create it
let exists = await utils.exists(absoluteFolderPath);
if (!exists) {
@@ -292,6 +297,11 @@ export class Project {
throw new Error(constants.fileAlreadyExists(path.parse(absoluteFilePath).name));
}
// check if file already has been added to sqlproj
if (this.files.find(f => f.relativePath.toLowerCase() === relativeFilePath.toLowerCase())) {
throw new Error(constants.fileAlreadyAddedToProject((relativeFilePath)));
}
// create the file if contents were passed in
if (contents) {
await fs.mkdir(path.dirname(absoluteFilePath), { recursive: true });