Skip to content

Commit 019e377

Browse files
Merge pull request #2510 from github/robertbrignull/use_contains_path
Use containsPath where possible
2 parents a03b3dc + cad651d commit 019e377

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

extensions/ql-vscode/src/data-extensions-editor/extension-pack-picker.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { DatabaseItem } from "../databases/local-databases";
1414
import { getQlPackPath, QLPACK_FILENAMES } from "../pure/ql";
1515
import { getErrorMessage } from "../pure/helpers-pure";
1616
import { ExtensionPack, ExtensionPackModelFile } from "./shared/extension-pack";
17+
import { containsPath } from "../pure/files";
1718

1819
const maxStep = 3;
1920

@@ -347,11 +348,7 @@ async function pickNewModelFile(
347348
return "File already exists";
348349
}
349350

350-
const notInExtensionPack = relative(
351-
extensionPack.path,
352-
path,
353-
).startsWith("..");
354-
if (notInExtensionPack) {
351+
if (!containsPath(extensionPack.path, path)) {
355352
return "File must be in the extension pack";
356353
}
357354

extensions/ql-vscode/src/databases/local-databases/database-item-impl.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import * as cli from "../../codeql-cli/cli";
33
import vscode from "vscode";
44
import { FullDatabaseOptions } from "./database-options";
5-
import { basename, dirname, extname, join, relative } from "path";
5+
import { basename, dirname, extname, join } from "path";
66
import {
77
decodeSourceArchiveUri,
88
encodeArchiveBasePath,
@@ -12,7 +12,7 @@ import {
1212
import { DatabaseItem, PersistedDatabaseItem } from "./database-item";
1313
import { isLikelyDatabaseRoot } from "./db-contents-heuristics";
1414
import { stat } from "fs-extra";
15-
import { pathsEqual } from "../../pure/files";
15+
import { containsPath, pathsEqual } from "../../pure/files";
1616
import { DatabaseContents } from "./database-contents";
1717

1818
export class DatabaseItemImpl implements DatabaseItem {
@@ -199,7 +199,7 @@ export class DatabaseItemImpl implements DatabaseItem {
199199
try {
200200
const stats = await stat(testPath);
201201
if (stats.isDirectory()) {
202-
return !relative(testPath, databasePath).startsWith("..");
202+
return containsPath(testPath, databasePath);
203203
} else {
204204
// database for /one/two/three/test.ql is at /one/two/three/three.testproj
205205
const testdir = dirname(testPath);

0 commit comments

Comments
 (0)