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

Package manager nullability fixes #5255

Merged
merged 24 commits into from
Jul 1, 2022
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
09d6f49
Add undefined to parameters in UpdatePackageDependencies
winstliu Jun 1, 2022
d8f9db4
Mark getRuntimeDependencyPackageUtils as nullable
winstliu Jun 1, 2022
3abd117
Default to empty string for rzls config
winstliu Jun 1, 2022
07df02e
Bump @types/yauzl for correct types
winstliu Jun 1, 2022
085c4b2
Coerce error types in ZipInstaller
winstliu Jun 1, 2022
36bba18
Use stricter types in proxy.ts
winstliu Jun 1, 2022
a3ebcf6
Add missing architecture to OmniSharp OSX Mono x64
winstliu Jun 1, 2022
b35ec38
Simplify PackageFilterer logic
winstliu Jun 1, 2022
241cef3
Remove nulls from PackageError
winstliu Jun 1, 2022
4531daf
Mark integrity as nullable in isValidDownload
winstliu Jun 1, 2022
7e2d319
Simplify getAbsolutePathPackagesToInstall
winstliu Jun 1, 2022
df711a2
Guard against missing headers in FileDownloader
winstliu Jun 1, 2022
ba7ec1b
Simplify logic in downloadAndInstallPackages
winstliu Jun 1, 2022
05755e2
Make binaries optional for AbsolutePathPackage
winstliu Jun 1, 2022
68eec1c
Pass boolean for NetworkSettings strictSSL
winstliu Jun 1, 2022
c81362c
Update Node types
winstliu Jun 1, 2022
60bdd5d
Update test typings
winstliu Jun 1, 2022
ea7a672
Fix tests
winstliu Jun 1, 2022
7909d35
Remove unnecssary conditional
winstliu Jun 1, 2022
c2333b9
Remove isBoolean
winstliu Jun 1, 2022
4f271b6
Remove unnecessary cast
winstliu Jun 1, 2022
94ca366
Make tasks nullable-aware
winstliu Jun 1, 2022
68fcae9
Some more cleanup in OmnisharpPackageCreator
winstliu Jun 5, 2022
5b8983c
Fix tests
winstliu Jun 5, 2022
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
8 changes: 4 additions & 4 deletions src/packageManager/AbsolutePath.ts
Original file line number Diff line number Diff line change
@@ -3,16 +3,16 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { isAbsolute, resolve } from "path";
import * as path from "path";

export class AbsolutePath {
constructor(public value: string) {
if (!isAbsolute(value)) {
if (!path.isAbsolute(value)) {
throw new Error("The path must be absolute");
}
}

public static getAbsolutePath(...pathSegments: string[]): AbsolutePath {
return new AbsolutePath(resolve(...pathSegments));
return new AbsolutePath(path.resolve(...pathSegments));
}
}
}
20 changes: 8 additions & 12 deletions src/packageManager/AbsolutePathPackage.ts
Original file line number Diff line number Diff line change
@@ -13,8 +13,8 @@ export class AbsolutePathPackage implements IPackage {
public url: string,
public platforms: string[],
public architectures: string[],
public binaries: AbsolutePath[],
public installPath: AbsolutePath,
public binaries?: AbsolutePath[],
public installTestPath?: AbsolutePath,
public fallbackUrl?: string,
public platformId?: string,
@@ -29,8 +29,8 @@ export class AbsolutePathPackage implements IPackage {
pkg.url,
pkg.platforms,
pkg.architectures,
getAbsoluteBinaries(pkg, extensionPath),
getAbsoluteInstallPath(pkg, extensionPath),
getAbsoluteBinaries(pkg, extensionPath),
getAbsoluteInstallTestPath(pkg, extensionPath),
pkg.fallbackUrl,
pkg.platformId,
@@ -40,21 +40,17 @@ export class AbsolutePathPackage implements IPackage {
}
}

function getAbsoluteInstallTestPath(pkg: Package, extensionPath: string): AbsolutePath {
if (pkg.installTestPath) {
function getAbsoluteInstallTestPath(pkg: Package, extensionPath: string): AbsolutePath | undefined {
if (pkg.installTestPath !== undefined) {
return AbsolutePath.getAbsolutePath(extensionPath, pkg.installTestPath);
}

return null;
return undefined;
}

function getAbsoluteBinaries(pkg: Package, extensionPath: string): AbsolutePath[] {
let basePath = getAbsoluteInstallPath(pkg, extensionPath).value;
if (pkg.binaries) {
return pkg.binaries.map(value => AbsolutePath.getAbsolutePath(basePath, value));
}

return null;
function getAbsoluteBinaries(pkg: Package, extensionPath: string): AbsolutePath[] | undefined {
const basePath = getAbsoluteInstallPath(pkg, extensionPath).value;
return pkg.binaries?.map(value => AbsolutePath.getAbsolutePath(basePath, value));
}

function getAbsoluteInstallPath(pkg: Package, extensionPath: string): AbsolutePath {
9 changes: 3 additions & 6 deletions src/packageManager/ZipInstaller.ts
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import { InstallationStart, ZipError } from "../omnisharp/loggingEvents";
import { NestedError } from '../NestedError';
import { AbsolutePath } from './AbsolutePath';

export async function InstallZip(buffer: Buffer, description: string, destinationInstallPath: AbsolutePath, binaries: AbsolutePath[], eventStream: EventStream): Promise<void> {
export async function InstallZip(buffer: Buffer, description: string, destinationInstallPath: AbsolutePath, binaries: AbsolutePath[] | undefined, eventStream: EventStream): Promise<void> {
eventStream.post(new InstallationStart(description));

return new Promise<void>((resolve, reject) => {
@@ -49,12 +49,9 @@ export async function InstallZip(buffer: Buffer, description: string, destinatio
try {
await mkdirp(path.dirname(absoluteEntryPath), 0o775);

let binaryPaths = binaries && binaries.map(binary => binary.value);

// Make sure executable files have correct permissions when extracted
let fileMode = binaryPaths && binaryPaths.indexOf(absoluteEntryPath) !== -1
? 0o755
: 0o664;
const binaryPaths = binaries?.map(binary => binary.value);
const fileMode = binaryPaths?.includes(absoluteEntryPath) ? 0o755 : 0o664;

readStream.pipe(fs.createWriteStream(absoluteEntryPath, { mode: fileMode }));
readStream.on('end', () => zipFile.readEntry());