From 3b0014ef981ef06d53dd74ff391c1be66d77e877 Mon Sep 17 00:00:00 2001 From: TheApplePieGod Date: Mon, 8 Jan 2024 12:21:16 -0500 Subject: [PATCH] Fix minor windows path issue --- client/src-tauri/src/main.rs | 7 ++++--- client/src/components/sidebar/runner/scaffold.ts | 9 +++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/client/src-tauri/src/main.rs b/client/src-tauri/src/main.rs index 2fcac07a..f407f83a 100644 --- a/client/src-tauri/src/main.rs +++ b/client/src-tauri/src/main.rs @@ -122,9 +122,10 @@ async fn tauri_api( Ok(vec!(final_path.to_str().unwrap().to_string())) }, "path.relative" => { - let final_path = RelativePath::new(&args[0]) - .relative(&args[1]); - Ok(vec!(final_path.to_string())) + let path_from = RelativePath::new(&args[0]); + let path_to = RelativePath::new(&args[1]); + let result = path_from.relative(path_to); + Ok(vec!(result.to_string())) }, "path.dirname" => { let path = Path::new(&args[0]).parent().unwrap_or(Path::new("")); diff --git a/client/src/components/sidebar/runner/scaffold.ts b/client/src/components/sidebar/runner/scaffold.ts index aa5f3c9f..59bf94bc 100644 --- a/client/src/components/sidebar/runner/scaffold.ts +++ b/client/src/components/sidebar/runner/scaffold.ts @@ -175,8 +175,13 @@ async function fetchData(scaffoldPath: string) { file.endsWith('RobotPlayer.scala') ) .map(async (file) => { - const relPath = await path.relative(sourcePath, file) - const botName = relPath.split(sep)[0] // Name of folder + // Relative path will contain the folder and filename, so we can split on the separator + // to get the folder name. We must first normalize the path to have forward slashes in the + // case of windows so the relative path function works correctly + const p1 = sourcePath.replace(/\\/g, '/') + const p2 = file.replace(/\\/g, '/') + const relPath = (await path.relative(p1, p2)).replace(/\\/g, '/') + const botName = relPath.split('/')[0] return botName }) )