File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed
Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ import {
4747 configEntryEquals ,
4848 RootPathAndLabel ,
4949} from "./types" ;
50+ import { normalizePathForOS } from "./utilities/normalizePath" ;
5051
5152export const SERIALIZED_FILE_EXTENSION = ".weaudit" ;
5253const DAY_LOG_FILENAME = ".weauditdaylog" ;
@@ -3315,6 +3316,28 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
33153316 ) ,
33163317 } as FullSerializedData ;
33173318
3319+ // Normalize all the paths from loaded files. These can come from different OSes with different path
3320+ // conventions. We do a best effort to match them to the current OS format.
3321+ fullParsedEntries . treeEntries . forEach ( ( entry ) => {
3322+ entry . locations . forEach ( ( loc ) => {
3323+ loc . path = normalizePathForOS ( rootPath , loc . path ) ;
3324+ } ) ;
3325+ } ) ;
3326+
3327+ fullParsedEntries . resolvedEntries . forEach ( ( entry ) => {
3328+ entry . locations . forEach ( ( loc ) => {
3329+ loc . path = normalizePathForOS ( rootPath , loc . path ) ;
3330+ } ) ;
3331+ } ) ;
3332+
3333+ fullParsedEntries . auditedFiles . forEach ( ( auditedFile ) => {
3334+ auditedFile . path = normalizePathForOS ( rootPath , auditedFile . path ) ;
3335+ } ) ;
3336+
3337+ fullParsedEntries . partiallyAuditedFiles ?. forEach ( ( partiallyAuditedFile ) => {
3338+ partiallyAuditedFile . path = normalizePathForOS ( rootPath , partiallyAuditedFile . path ) ;
3339+ } ) ;
3340+
33183341 if ( update ) {
33193342 if ( add ) {
33203343 // Remove potential entries of username which appear on the tree.
Original file line number Diff line number Diff line change 1+ import * as path from "path" ;
2+ import * as fs from "fs" ;
3+
4+ /**
5+ * A method that normalizes the slashes in a path based on current operating system.
6+ *
7+ * @param wsRoot - The workspace root path to resolve relative paths
8+ * @param filePath - The file path string to normalize
9+ * @returns The path with slashes normalized for the current operating system
10+ */
11+ export function normalizePathForOS ( wsRoot : string , filePath : string ) : string {
12+ if ( process . platform === "win32" && filePath . includes ( "/" ) ) {
13+ // Unix-style paths on Windows
14+ return path . normalize ( filePath ) ;
15+ } else if ( process . platform !== "win32" && filePath . includes ( "\\" ) ) {
16+ if ( fs . existsSync ( path . join ( wsRoot , filePath ) ) ) {
17+ // Hateful edge case, this is a unix-style path with backslashes in the file name.
18+ return filePath ;
19+ } else {
20+ // Windows path on non-windows OS
21+ return filePath . replace ( / \\ / g, "/" ) ;
22+ }
23+ }
24+ return filePath ;
25+ }
You can’t perform that action at this time.
0 commit comments