Skip to content

Commit

Permalink
(fix): handled partial download failure case
Browse files Browse the repository at this point in the history
  • Loading branch information
samyakkkk committed Apr 23, 2024
1 parent 3fa8bc0 commit fb5d55e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 3 additions & 1 deletion vscode/src/repository/http-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export async function refreshAccessToken(refreshToken: string): Promise<string>


export async function downloadFile(url: string, destinationPath: string, onProgress: (progress: number) => void): Promise<void> {
/// 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({
Expand Down Expand Up @@ -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`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit fb5d55e

Please sign in to comment.