|
1 | 1 | import { pathExists, stat, readdir, opendir } from "fs-extra"; |
2 | | -import { join, resolve } from "path"; |
| 2 | +import { isAbsolute, join, relative, resolve } from "path"; |
3 | 3 |
|
4 | 4 | /** |
5 | 5 | * Recursively finds all .ql files in this set of Uris. |
@@ -51,36 +51,32 @@ export async function getDirectoryNamesInsidePath( |
51 | 51 | return dirNames; |
52 | 52 | } |
53 | 53 |
|
54 | | -function normalizePath(path: string, platform: NodeJS.Platform): string { |
| 54 | +function normalizePath(path: string): string { |
55 | 55 | // On Windows, "C:/", "C:\", and "c:/" are all equivalent. We need |
56 | 56 | // to normalize the paths to ensure they all get resolved to the |
57 | 57 | // same format. On Windows, we also need to do the comparison |
58 | 58 | // case-insensitively. |
59 | 59 | path = resolve(path); |
60 | | - if (platform === "win32") { |
| 60 | + if (process.platform === "win32") { |
61 | 61 | path = path.toLowerCase(); |
62 | 62 | } |
63 | 63 | return path; |
64 | 64 | } |
65 | 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); |
| 66 | +export function pathsEqual(path1: string, path2: string): boolean { |
| 67 | + return normalizePath(path1) === normalizePath(path2); |
72 | 68 | } |
73 | 69 |
|
74 | 70 | /** |
75 | | - * Returns true if path1 contains path2. |
| 71 | + * Returns true if `parent` contains `child`, or if they are equal. |
76 | 72 | */ |
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), |
| 73 | +export function containsPath(parent: string, child: string): boolean { |
| 74 | + const relativePath = relative(parent, child); |
| 75 | + return ( |
| 76 | + !relativePath.startsWith("..") && |
| 77 | + // On windows, if the two paths are in different drives, then the |
| 78 | + // relative path will be an absolute path to the other drive. |
| 79 | + !isAbsolute(relativePath) |
84 | 80 | ); |
85 | 81 | } |
86 | 82 |
|
|
0 commit comments