10422: fix: overwrite files when calling `patchelf` r=lnicola a=lnicola

Fixes #10379

bors r+

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
bors[bot] 2021-10-02 07:08:48 +00:00 committed by GitHub
commit 59c758d0cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -286,21 +286,24 @@ async function patchelf(dest: vscode.Uri): Promise<void> {
}
`;
const origFile = vscode.Uri.file(dest.fsPath + "-orig");
await vscode.workspace.fs.rename(dest, origFile);
progress.report({ message: "Patching executable", increment: 20 });
await new Promise((resolve, reject) => {
const handle = exec(`nix-build -E - --argstr srcStr '${origFile.fsPath}' -o '${dest.fsPath}'`,
(err, stdout, stderr) => {
if (err != null) {
reject(Error(stderr));
} else {
resolve(stdout);
}
});
handle.stdin?.write(expression);
handle.stdin?.end();
});
await vscode.workspace.fs.delete(origFile);
await vscode.workspace.fs.rename(dest, origFile, { overwrite: true });
try {
progress.report({ message: "Patching executable", increment: 20 });
await new Promise((resolve, reject) => {
const handle = exec(`nix-build -E - --argstr srcStr '${origFile.fsPath}' -o '${dest.fsPath}'`,
(err, stdout, stderr) => {
if (err != null) {
reject(Error(stderr));
} else {
resolve(stdout);
}
});
handle.stdin?.write(expression);
handle.stdin?.end();
});
} finally {
await vscode.workspace.fs.delete(origFile);
}
}
);
}