From 56e128a979082de4ea58b7739049405fbc43f394 Mon Sep 17 00:00:00 2001 From: wxb1ank Date: Tue, 15 Jun 2021 13:29:02 -0400 Subject: fix: clean-up #8951 --- editors/code/src/main.ts | 16 +++++++++------- editors/code/src/net.ts | 8 ++++---- editors/code/src/toolchain.ts | 16 ++++++++++++---- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index f58d26215..049d6cb8e 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -158,7 +158,9 @@ export async function deactivate() { } async function bootstrap(config: Config, state: PersistentState): Promise { - await vscode.workspace.fs.createDirectory(config.globalStorageUri); + try { + await vscode.workspace.fs.createDirectory(config.globalStorageUri); + } catch {} if (!config.currentExtensionIsNightly) { await state.updateNightlyReleaseId(undefined); @@ -277,11 +279,11 @@ async function patchelf(dest: vscode.Uri): Promise { ''; } `; - const origFile = vscode.Uri.file(dest.path + "-orig"); + const origFile = vscode.Uri.file(dest.fsPath + "-orig"); await vscode.workspace.fs.rename(dest, origFile); progress.report({ message: "Patching executable", increment: 20 }); await new Promise((resolve, reject) => { - const handle = exec(`nix-build -E - --argstr srcStr '${origFile.path}' -o '${dest.path}'`, + const handle = exec(`nix-build -E - --argstr srcStr '${origFile.fsPath}' -o '${dest.fsPath}'`, (err, stdout, stderr) => { if (err != null) { reject(Error(stderr)); @@ -338,14 +340,14 @@ async function getServer(config: Config, state: PersistentState): Promise { try { const contents = (await vscode.workspace.fs.readFile(vscode.Uri.file("/etc/os-release"))).toString(); return contents.indexOf("ID=nixos") !== -1; - } catch (e) { + } catch { return false; } } diff --git a/editors/code/src/net.ts b/editors/code/src/net.ts index 5c48c74e8..722dab756 100644 --- a/editors/code/src/net.ts +++ b/editors/code/src/net.ts @@ -91,7 +91,7 @@ export async function download(opts: DownloadOpts) { // to prevent partially downloaded files when user kills vscode // This also avoids overwriting running executables const randomHex = crypto.randomBytes(5).toString("hex"); - const rawDest = path.parse(opts.dest.path); + const rawDest = path.parse(opts.dest.fsPath); const tempFilePath = vscode.Uri.joinPath(vscode.Uri.file(rawDest.dir), `${rawDest.name}${randomHex}`); await vscode.window.withProgress( @@ -116,7 +116,7 @@ export async function download(opts: DownloadOpts) { } ); - await vscode.workspace.fs.rename(tempFilePath, opts.dest); + await vscode.workspace.fs.rename(tempFilePath, opts.dest, { overwrite: true }); } async function downloadFile( @@ -148,7 +148,7 @@ async function downloadFile( const totalBytes = Number(res.headers.get('content-length')); assert(!Number.isNaN(totalBytes), "Sanity check of content-length protocol"); - log.debug("Downloading file of", totalBytes, "bytes size from", urlString, "to", destFilePath.path); + log.debug("Downloading file of", totalBytes, "bytes size from", urlString, "to", destFilePath.fsPath); let readBytes = 0; res.body.on("data", (chunk: Buffer) => { @@ -156,7 +156,7 @@ async function downloadFile( onProgress(readBytes, totalBytes); }); - const destFileStream = fs.createWriteStream(destFilePath.path, { mode }); + const destFileStream = fs.createWriteStream(destFilePath.fsPath, { mode }); const srcStream = gunzip ? res.body.pipe(zlib.createGunzip()) : res.body; await pipeline(srcStream, destFileStream); diff --git a/editors/code/src/toolchain.ts b/editors/code/src/toolchain.ts index 902d0ddda..355dd76fe 100644 --- a/editors/code/src/toolchain.ts +++ b/editors/code/src/toolchain.ts @@ -159,7 +159,7 @@ export const getPathForExecutable = memoize( // it is not mentioned in docs and cannot be infered by the type signature... const standardPath = vscode.Uri.joinPath(vscode.Uri.file(os.homedir()), ".cargo", "bin", executableName); - if (isFile(standardPath.path)) return standardPath.path; + if (isFileAtUri(standardPath)) return standardPath.fsPath; } catch (err) { log.error("Failed to read the fs info", err); } @@ -177,9 +177,17 @@ function lookupInPath(exec: string): boolean { : [candidate]; }); - return candidates.some(isFile); + return candidates.some(isFileAtPath); } -async function isFile(path: string): Promise { - return ((await vscode.workspace.fs.stat(vscode.Uri.file(path))).type & vscode.FileType.File) !== 0; +async function isFileAtPath(path: string): Promise { + return isFileAtUri(vscode.Uri.file(path)); +} + +async function isFileAtUri(uri: vscode.Uri): Promise { + try { + return ((await vscode.workspace.fs.stat(uri)).type & vscode.FileType.File) !== 0; + } catch { + return false; + } } -- cgit v1.2.3