Skip to content

Commit 1d27598

Browse files
author
Dave Bartolomeo
committed
Fix PR feedback
1 parent 55306c9 commit 1d27598

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

extensions/ql-vscode/src/common/short-paths.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,38 @@ import { basename, dirname, join, normalize, resolve } from "path";
33
import { lstat, readdir } from "fs/promises";
44
import type { BaseLogger } from "./logging";
55

6+
/**
7+
* Expands a path that potentially contains 8.3 short names (e.g. "C:\PROGRA~1" instead of "C:\Program Files").
8+
*
9+
* See https://en.wikipedia.org/wiki/8.3_filename if you're not familiar with Windows 8.3 short names.
10+
*
11+
* @param shortPath The path to expand.
12+
* @returns A normalized, absolute path, with any short components expanded.
13+
*/
14+
export async function expandShortPaths(
15+
shortPath: string,
16+
logger: BaseLogger,
17+
): Promise<string> {
18+
const absoluteShortPath = normalize(resolve(shortPath));
19+
if (platform() !== "win32") {
20+
// POSIX doesn't have short paths.
21+
return absoluteShortPath;
22+
}
23+
24+
void logger.log(`Expanding short paths in: ${absoluteShortPath}`);
25+
// A quick check to see if there might be any short components.
26+
// There might be a case where a short component doesn't contain a `~`, but if there is, I haven't
27+
// found it.
28+
// This may find long components that happen to have a '~', but that's OK.
29+
if (absoluteShortPath.indexOf("~") < 0) {
30+
// No short components to expand.
31+
void logger.log(`Skipping due to no short components`);
32+
return absoluteShortPath;
33+
}
34+
35+
return await expandShortPathRecursive(absoluteShortPath, logger);
36+
}
37+
638
/**
739
* Expand a single short path component
840
* @param dir The absolute path of the directory containing the short path component.
@@ -83,35 +115,3 @@ async function expandShortPathRecursive(
83115
const longBase = await expandShortPathComponent(dir, shortBase, logger);
84116
return join(dir, longBase);
85117
}
86-
87-
/**
88-
* Expands a path that potentially contains 8.3 short names (e.g. "C:\PROGRA~1" instead of "C:\Program Files").
89-
*
90-
* See https://en.wikipedia.org/wiki/8.3_filename if you're not familiar with Windows 8.3 short names.
91-
*
92-
* @param shortPath The path to expand.
93-
* @returns A normalized, absolute path, with any short components expanded.
94-
*/
95-
export async function expandShortPaths(
96-
shortPath: string,
97-
logger: BaseLogger,
98-
): Promise<string> {
99-
const absoluteShortPath = normalize(resolve(shortPath));
100-
if (platform() !== "win32") {
101-
// POSIX doesn't have short paths.
102-
return absoluteShortPath;
103-
}
104-
105-
void logger.log(`Expanding short paths in: ${absoluteShortPath}`);
106-
// A quick check to see if there might be any short components.
107-
// There might be a case where a short component doesn't contain a `~`, but if there is, I haven't
108-
// found it.
109-
// This may find long components that happen to have a '~', but that's OK.
110-
if (absoluteShortPath.indexOf("~") < 0) {
111-
// No short components to expand.
112-
void logger.log(`Skipping due to no short components`);
113-
return absoluteShortPath;
114-
}
115-
116-
return await expandShortPathRecursive(absoluteShortPath, logger);
117-
}

0 commit comments

Comments
 (0)