Skip to content

Commit c7f4647

Browse files
committed
Move unlink on download into download function
Since this is required by all callsites its easier to have it in the function itself.
1 parent df4d595 commit c7f4647

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

editors/code/src/main.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,11 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
200200
const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix");
201201

202202
await downloadWithRetryDialog(state, async () => {
203-
// Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
204-
await fs.unlink(dest).catch(err => {
205-
if (err.code !== "ENOENT") throw err;
206-
});
207-
208203
await download({
209204
url: artifact.browser_download_url,
210205
dest,
211206
progressTitle: "Downloading rust-analyzer extension",
207+
overwrite: true,
212208
});
213209
});
214210

@@ -330,17 +326,13 @@ async function getServer(config: Config, state: PersistentState): Promise<string
330326
assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
331327

332328
await downloadWithRetryDialog(state, async () => {
333-
// Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
334-
await fs.unlink(dest).catch(err => {
335-
if (err.code !== "ENOENT") throw err;
336-
});
337-
338329
await download({
339330
url: artifact.browser_download_url,
340331
dest,
341332
progressTitle: "Downloading rust-analyzer server",
342333
gunzip: true,
343-
mode: 0o755
334+
mode: 0o755,
335+
overwrite: true,
344336
});
345337
});
346338

editors/code/src/net.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ interface DownloadOpts {
7676
dest: string;
7777
mode?: number;
7878
gunzip?: boolean;
79+
overwrite?: boolean,
7980
}
8081

8182
export async function download(opts: DownloadOpts) {
@@ -85,6 +86,13 @@ export async function download(opts: DownloadOpts) {
8586
const randomHex = crypto.randomBytes(5).toString("hex");
8687
const tempFile = path.join(dest.dir, `${dest.name}${randomHex}`);
8788

89+
if (opts.overwrite) {
90+
// Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
91+
await fs.promises.unlink(opts.dest).catch(err => {
92+
if (err.code !== "ENOENT") throw err;
93+
});
94+
}
95+
8896
await vscode.window.withProgress(
8997
{
9098
location: vscode.ProgressLocation.Notification,

0 commit comments

Comments
 (0)