vscode: remove chmod in favour of an option to createWriteStream()

This commit is contained in:
Veetaha
2020-02-11 22:34:52 +02:00
parent 00e672a51b
commit b834b37682
2 changed files with 8 additions and 5 deletions

View File

@@ -3,7 +3,7 @@ import * as fs from "fs";
import { strict as assert } from "assert"; import { strict as assert } from "assert";
/** /**
* Downloads file from `url` and stores it at `destFilePath`. * Downloads file from `url` and stores it at `destFilePath` with `destFilePermissions`.
* `onProgress` callback is called on recieveing each chunk of bytes * `onProgress` callback is called on recieveing each chunk of bytes
* to track the progress of downloading, it gets the already read and total * to track the progress of downloading, it gets the already read and total
* amount of bytes to read as its parameters. * amount of bytes to read as its parameters.
@@ -11,6 +11,7 @@ import { strict as assert } from "assert";
export async function downloadFile( export async function downloadFile(
url: string, url: string,
destFilePath: fs.PathLike, destFilePath: fs.PathLike,
destFilePermissions: number,
onProgress: (readBytes: number, totalBytes: number) => void onProgress: (readBytes: number, totalBytes: number) => void
): Promise<void> { ): Promise<void> {
const res = await fetch(url); const res = await fetch(url);
@@ -35,6 +36,9 @@ export async function downloadFile(
onProgress(readBytes, totalBytes); onProgress(readBytes, totalBytes);
}) })
.on("error", reject) .on("error", reject)
.pipe(fs.createWriteStream(destFilePath).on("close", resolve)) .pipe(fs
.createWriteStream(destFilePath, { mode: destFilePermissions })
.on("close", resolve)
)
); );
} }

View File

@@ -35,7 +35,8 @@ export async function downloadLatestLanguageServer(
}, },
async (progress, _cancellationToken) => { async (progress, _cancellationToken) => {
let lastPrecentage = 0; let lastPrecentage = 0;
await downloadFile(downloadUrl, installationPath, throttle( const filePermissions = 0o755; // (rwx, r_x, r_x)
await downloadFile(downloadUrl, installationPath, filePermissions, throttle(
200, 200,
/* noTrailing: */ true, /* noTrailing: */ true,
(readBytes, totalBytes) => { (readBytes, totalBytes) => {
@@ -51,8 +52,6 @@ export async function downloadLatestLanguageServer(
} }
); );
console.timeEnd("Downloading ra_lsp_server"); console.timeEnd("Downloading ra_lsp_server");
await fs.chmod(installationPath, 0o755); // Set (rwx, r_x, r_x) permissions
} }
export async function ensureLanguageServerBinary( export async function ensureLanguageServerBinary(
langServerSource: null | BinarySource langServerSource: null | BinarySource