Download artifacts into tmp dir

This commit is contained in:
Veetaha 2020-06-20 15:38:08 +03:00
parent 0f7961d557
commit dceb81856e
2 changed files with 60 additions and 11 deletions

View file

@ -42,7 +42,16 @@ export async function activate(context: vscode.ExtensionContext) {
const config = new Config(context);
const state = new PersistentState(context.globalState);
const serverPath = await bootstrap(config, state);
const serverPath = await bootstrap(config, state).catch(err => {
let message = "Failed to bootstrap rust-analyzer.";
if (err.code === "EBUSY" || err.code === "ETXTBSY") {
message += " Other vscode windows might be using rust-analyzer, " +
"you should close them and reload this window to retry.";
}
message += " Open \"Help > Toggle Developer Tools > Console\" to see the logs";
log.error("Bootstrap error", err);
throw new Error(message);
});
const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
if (workspaceFolder === undefined) {
@ -285,6 +294,11 @@ async function getServer(config: Config, state: PersistentState): Promise<string
const artifact = release.assets.find(artifact => artifact.name === binaryName);
assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
// Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
await fs.unlink(dest).catch(err => {
if (err.code !== "ENOENT") throw err;
});
await download(artifact.browser_download_url, dest, "Downloading rust-analyzer server", { mode: 0o755 });
// Patching executable if that's NixOS.