Skip to content

Commit

Permalink
prevent compilation db corruption (microsoft#3214)
Browse files Browse the repository at this point in the history
    - if copyCompileCommands is equal to default db path,
    we need to avoid the copy otherwise it would  copy on itself
  • Loading branch information
parniere committed Dec 18, 2023
1 parent 6876476 commit a25e43b
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/cmakeProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1221,20 +1221,22 @@ export class CMakeProject {
// Now try to copy the compdb to the user-requested path
const copyDest = this.workspaceContext.config.copyCompileCommands;
const expandedDest = await expandString(copyDest, opts);
const parentDir = path.dirname(expandedDest);
try {
log.debug(localize('copy.compile.commands', 'Copying {2} from {0} to {1}', compdbPath, expandedDest, 'compile_commands.json'));
await fs.mkdir_p(parentDir);
if (compdbPath !== expandedDest) {
const parentDir = path.dirname(expandedDest);
try {
await fs.copyFile(compdbPath, expandedDest);
log.debug(localize('copy.compile.commands', 'Copying {2} from {0} to {1}', compdbPath, expandedDest, 'compile_commands.json'));
await fs.mkdir_p(parentDir);
try {
await fs.copyFile(compdbPath, expandedDest);
} catch (e: any) {
// Just display the error. It's the best we can do.
void vscode.window.showErrorMessage(localize('failed.to.copy', 'Failed to copy {0} to {1}: {2}', `"${compdbPath}"`, `"${expandedDest}"`, e.toString()));
}
} catch (e: any) {
// Just display the error. It's the best we can do.
void vscode.window.showErrorMessage(localize('failed.to.copy', 'Failed to copy {0} to {1}: {2}', `"${compdbPath}"`, `"${expandedDest}"`, e.toString()));
void vscode.window.showErrorMessage(localize('failed.to.create.parent.directory.1',
'Tried to copy {0} to {1}, but failed to create the parent directory {2}: {3}',
`"${compdbPath}"`, `"${expandedDest}"`, `"${parentDir}"`, e.toString()));
}
} catch (e: any) {
void vscode.window.showErrorMessage(localize('failed.to.create.parent.directory.1',
'Tried to copy {0} to {1}, but failed to create the parent directory {2}: {3}',
`"${compdbPath}"`, `"${expandedDest}"`, `"${parentDir}"`, e.toString()));
}
}
} else if (this.workspaceContext.config.copyCompileCommands) {
Expand Down

0 comments on commit a25e43b

Please sign in to comment.