Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixes permission issue when renaming executable for windows #260

Merged
merged 4 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions vscode/src/repository/http-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@


export async function refreshAccessToken(refreshToken: string): Promise<string> {
const response = await makeHttpRequest<{ access_token: string }>({

Check warning on line 58 in vscode/src/repository/http-utils.ts

View workflow job for this annotation

GitHub Actions / lint

Type Property name `access_token` must match one of the following formats: camelCase
url: baseUrl + '/account/github/refresh', method: 'POST',
headers: {
// eslint-disable-next-line @typescript-eslint/naming-convention
Expand All @@ -67,6 +67,7 @@


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,6 +98,6 @@
writer.on('finish', resolve);
writer.on('error', reject);
});

fs.renameSync(tempFilePath, destinationPath); // Only write file to destination path once download finishes
}
// Downloaded executable is saved as a pre-downloaded file which will be renamed in the next session.
fs.renameSync(tempFilePath, `${destinationPath}.pre-downloaded`);
}
28 changes: 17 additions & 11 deletions vscode/src/utilities/commanddash-integration/dart-cli-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { EventEmitter } from 'events';
import { Task } from './task';
import { join } from 'path';
import { chmod, existsSync, unlink } from 'fs';
import { chmod, chmodSync, existsSync, renameSync, unlink } from 'fs';
import { downloadFile, makeHttpRequest } from '../../repository/http-utils';
import { AxiosRequestConfig } from 'axios';
import * as vscode from 'vscode';
Expand All @@ -26,16 +26,6 @@
return;
}
await downloadFile(response['url'], executablePath, onProgress);
if (platform === 'darwin' || platform === 'linux') {
// Downloaded file is required to be coverted to an executable.
return new Promise<void>((resolve, reject) => {
chmod(executablePath, '755', (err) => {
if (err) { reject(err); }
console.log('The permissions for the executable have been set');
resolve();
});
});
}
}

export async function deleteExecutable(executablePath: string): Promise<void> {
Expand Down Expand Up @@ -115,8 +105,24 @@
await deleteExecutable(this.executablePath);
}

private renameTempToExecutable(tempFilePath: string) {
renameSync(tempFilePath, this.executablePath);
const platform = os.platform();
if (platform === 'darwin' || platform === 'linux') {
// Downloaded file is required to be coverted to an executable.
chmodSync(this.executablePath, '755');
}
}

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}.pre-downloaded`;
if (existsSync(tempFilePath)) {
this.renameTempToExecutable(tempFilePath);
}


this.proc = child_process.spawn(this.executablePath, ['process']);

let buffer = '';
Expand Down Expand Up @@ -342,7 +348,7 @@

try {
/// Request the client to process the task and handle result or error
const response = await task.run({ kind: "random_task_with_step", data: { current_embeddings: {} } });

Check warning on line 351 in vscode/src/utilities/commanddash-integration/dart-cli-client.ts

View workflow job for this annotation

GitHub Actions / lint

Object Literal Property name `current_embeddings` must match one of the following formats: camelCase
console.log("Processing completed: ", response);
} catch (error) {
console.error("Processing error: ", error);
Expand Down
Loading