Skip to content

Commit

Permalink
Fix path failure preventing trace from opening
Browse files Browse the repository at this point in the history
When doing some testing on an internal extension relying, I
noticed that we could no longer use the Open With TraceViewer
command on Windows due to an invalid path failing (worked on Linux).

I was able to trace the cause of this it to some code that uses
.path instead of .fsPath, which is intended for use with the
filesystem and scrubs out improper path values  (which is
what caused our error!). I also changed some other path calculations to
be less error prone across platforms by using the path API.

This fixes a critical issue which prevents users from opening traces
in some cases.

Signed-off-by: Dylan Leclair <[email protected]>

QVSC-760: fix basename calculation
  • Loading branch information
dleclairbb committed Oct 26, 2023
1 parent b2c8f77 commit 32f2b75
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
18 changes: 9 additions & 9 deletions vscode-trace-extension/src/trace-explorer/trace-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,16 @@ export const fileHandler =
return;
}

const uri: string = resolvedTraceURI.path;
if (!uri) {
const filePath: string = resolvedTraceURI.fsPath;
if (!filePath) {
traceLogger.addLogMessage(
'Cannot open trace: could not retrieve path from URI for trace ' + resolvedTraceURI,
fileHandler.name
);
return;
}

const name = uri.substring(uri.lastIndexOf('/') + 1);
const name = path.basename(filePath);
const panel = TraceViewerPanel.createOrShow(context.extensionUri, name, undefined);

progress.report({ message: ProgressMessages.FINDING_TRACES, increment: 10 });
Expand All @@ -187,11 +187,11 @@ export const fileHandler =
if (fileStat) {
if (fileStat.type === vscode.FileType.Directory) {
// Find recursively CTF traces
const foundTraces = await findTraces(uri);
const foundTraces = await findTraces(filePath);
foundTraces.forEach(trace => tracesArray.push(trace));
} else {
// Open single trace file
tracesArray.push(uri);
tracesArray.push(filePath);
}
}

Expand All @@ -208,7 +208,7 @@ export const fileHandler =
progress.report({ message: ProgressMessages.OPENING_TRACES, increment: 20 });
const traces = new Array<TspTrace>();
for (let i = 0; i < tracesArray.length; i++) {
const traceName = tracesArray[i].substring(tracesArray[i].lastIndexOf('/') + 1);
const traceName = path.basename(tracesArray[i]);
const trace = await traceManager.openTrace(tracesArray[i], traceName);
if (trace) {
traces.push(trace);
Expand Down Expand Up @@ -291,7 +291,7 @@ const findTraces = async (directory: string): Promise<string[]> => {
const childrenArr = await vscode.workspace.fs.readDirectory(uri);
for (const child of childrenArr) {
if (child[1] === vscode.FileType.Directory) {
const subTraces = await findTraces(directory + '/' + child[0]);
const subTraces = await findTraces(path.join(directory, child[0]));
subTraces.forEach(trace => traces.push(trace));
}
}
Expand All @@ -311,8 +311,8 @@ const isCtf = async (directory: string): Promise<boolean> => {
};

function getProgressBarTitle(traceUri: vscode.Uri | undefined): string {
if (!traceUri || !traceUri.path) {
if (!traceUri || !traceUri.fsPath) {
return 'undefined';
}
return traceUri.path.substring(traceUri.path.lastIndexOf('/') + 1);
return path.basename(traceUri.fsPath);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as vscode from 'vscode';
import * as path from 'path';
import { Experiment } from 'tsp-typescript-client/lib/models/experiment';
import { getTspClientUrl, getTraceServerUrl } from '../utils/tspClient';
import { TraceServerConnectionStatusService } from '../utils/trace-server-status';
Expand Down Expand Up @@ -115,7 +116,7 @@ export class TraceViewerPanel {
private static async saveTraceCsv(csvData: string, defaultFileName: string) {
const saveDialogOptions = {
defaultUri: vscode.workspace.workspaceFolders
? vscode.Uri.file(vscode.workspace.workspaceFolders[0].uri.path + '/' + defaultFileName)
? vscode.Uri.file(path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, defaultFileName))
: undefined,
saveLabel: 'Save as CSV',
filters: {
Expand Down

0 comments on commit 32f2b75

Please sign in to comment.