From fb5d55edb118e80265d14c01656c7a7ecba18ec9 Mon Sep 17 00:00:00 2001 From: Samyak Jain <56000318+samyakkkk@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:26:17 +0530 Subject: [PATCH] (fix): handled partial download failure case --- vscode/src/repository/http-utils.ts | 4 +++- .../src/utilities/commanddash-integration/dart-cli-client.ts | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/vscode/src/repository/http-utils.ts b/vscode/src/repository/http-utils.ts index d4221c5b..de3fbf14 100644 --- a/vscode/src/repository/http-utils.ts +++ b/vscode/src/repository/http-utils.ts @@ -67,6 +67,7 @@ export async function refreshAccessToken(refreshToken: string): Promise export async function downloadFile(url: string, destinationPath: string, onProgress: (progress: number) => void): Promise { + /// First download on a temp path. This prevents from converting partial downloaded files (due to interruption) into executables. const tempFilePath = `${destinationPath}.tmp`; const response = await axios({ @@ -97,5 +98,6 @@ export async function downloadFile(url: string, destinationPath: string, onProgr writer.on('finish', resolve); writer.on('error', reject); }); - // Downloaded executable is saved as a temporory file. This will be renamed in the next session. + // Downloaded executable is saved as a pre-downloaded file which will be renamed in the next session. + fs.renameSync(tempFilePath, `${destinationPath}.pre-downloaded`); } \ No newline at end of file diff --git a/vscode/src/utilities/commanddash-integration/dart-cli-client.ts b/vscode/src/utilities/commanddash-integration/dart-cli-client.ts index b233db61..33683f99 100644 --- a/vscode/src/utilities/commanddash-integration/dart-cli-client.ts +++ b/vscode/src/utilities/commanddash-integration/dart-cli-client.ts @@ -26,7 +26,6 @@ async function setupExecutable(clientVersion: string, executablePath: string, ex return; } await downloadFile(response['url'], executablePath, onProgress); - } export async function deleteExecutable(executablePath: string): Promise { @@ -118,7 +117,7 @@ export class DartCLIClient { public connect() { // Verify the presence of the temporary file, indicating a downloaded update during the last IDE session. // Proceed with updating the executable if applicable. - const tempFilePath = `${this.executablePath}.tmp`; + const tempFilePath = `${this.executablePath}.pre-downloaded`; if (existsSync(tempFilePath)) { this.renameTempToExecutable(tempFilePath); }