Skip to content

Commit 9290f57

Browse files
committed
Use normalized path for checking inclusion
1 parent a414213 commit 9290f57

2 files changed

Lines changed: 27 additions & 11 deletions

File tree

extensions/ql-vscode/src/databases/local-databases.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { DisposableObject } from "../pure/disposable-object";
2424
import { Logger, extLogger } from "../common";
2525
import { asError, getErrorMessage } from "../pure/helpers-pure";
2626
import { QueryRunner } from "../query-server";
27-
import { pathsEqual } from "../pure/files";
27+
import { containsPath, pathsEqual } from "../pure/files";
2828
import { redactableError } from "../pure/errors";
2929
import {
3030
getAutogenerateQlPacks,
@@ -1157,7 +1157,7 @@ export class DatabaseManager extends DisposableObject {
11571157
// but storagePath will have an uppercase drive letter. Be sure to compare
11581158
// URIs to URIs only
11591159
if (storageUri) {
1160-
return uri.fsPath.startsWith(storageUri.fsPath);
1160+
return containsPath(storageUri.fsPath, uri.fsPath, process.platform);
11611161
}
11621162
return false;
11631163
}

extensions/ql-vscode/src/pure/files.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,37 @@ export async function getDirectoryNamesInsidePath(
5151
return dirNames;
5252
}
5353

54-
export function pathsEqual(
55-
path1: string,
56-
path2: string,
57-
platform: NodeJS.Platform,
58-
): boolean {
54+
function normalizePath(path: string, platform: NodeJS.Platform): string {
5955
// On Windows, "C:/", "C:\", and "c:/" are all equivalent. We need
6056
// to normalize the paths to ensure they all get resolved to the
6157
// same format. On Windows, we also need to do the comparison
6258
// case-insensitively.
63-
path1 = resolve(path1);
64-
path2 = resolve(path2);
59+
path = resolve(path);
6560
if (platform === "win32") {
66-
return path1.toLowerCase() === path2.toLowerCase();
61+
path = path.toLowerCase();
6762
}
68-
return path1 === path2;
63+
return path;
64+
}
65+
66+
export function pathsEqual(
67+
path1: string,
68+
path2: string,
69+
platform: NodeJS.Platform,
70+
): boolean {
71+
return normalizePath(path1, platform) === normalizePath(path2, platform);
72+
}
73+
74+
/**
75+
* Returns true if path1 contains path2.
76+
*/
77+
export function containsPath(
78+
path1: string,
79+
path2: string,
80+
platform: NodeJS.Platform,
81+
): boolean {
82+
return normalizePath(path2, platform).startsWith(
83+
normalizePath(path1, platform),
84+
);
6985
}
7086

7187
export async function readDirFullPaths(path: string): Promise<string[]> {

0 commit comments

Comments
 (0)