From 48ad192a3c907b66a016e8278bbd3da8f28abcf3 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Sun, 9 Jun 2024 14:09:57 -0400 Subject: [PATCH] fix(win): Use posix.join in constructing FileTrees The internal representation of file trees uses relative paths. For simplicity, we should ensure that these always use POSIX separators. --- bids-validator/src/deps/path.ts | 1 + bids-validator/src/files/browser.ts | 4 ++-- bids-validator/src/files/deno.ts | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bids-validator/src/deps/path.ts b/bids-validator/src/deps/path.ts index 244fb7b25..0c24472c3 100644 --- a/bids-validator/src/deps/path.ts +++ b/bids-validator/src/deps/path.ts @@ -5,6 +5,7 @@ export { basename, dirname, extname, + posix, fromFileUrl, parse, SEPARATOR_PATTERN, diff --git a/bids-validator/src/files/browser.ts b/bids-validator/src/files/browser.ts index 44ebb6eb9..190a0cb8a 100644 --- a/bids-validator/src/files/browser.ts +++ b/bids-validator/src/files/browser.ts @@ -1,7 +1,7 @@ import { BIDSFile } from '../types/file.ts' import { FileTree } from '../types/filetree.ts' import { FileIgnoreRules } from './ignore.ts' -import { parse, join, SEPARATOR_PATTERN } from '../deps/path.ts' +import { parse, posix, SEPARATOR_PATTERN } from '../deps/path.ts' /** * Browser implement of BIDSFile wrapping native File/FileList types @@ -68,7 +68,7 @@ export function fileListToTree(files: File[]): Promise { } else { // Otherwise make a new level and continue if needed const newTree = new FileTree( - join(currentLevelTree.path, level), + posix.join(currentLevelTree.path, level), level, currentLevelTree, ) diff --git a/bids-validator/src/files/deno.ts b/bids-validator/src/files/deno.ts index ca15c4358..852e173a6 100644 --- a/bids-validator/src/files/deno.ts +++ b/bids-validator/src/files/deno.ts @@ -1,7 +1,7 @@ /** * Deno specific implementation for reading files */ -import { join, basename } from '../deps/path.ts' +import { posix, join, basename } from '../deps/path.ts' import { BIDSFile } from '../types/file.ts' import { FileTree } from '../types/filetree.ts' import { requestReadPermission } from '../setup/requestPermissions.ts' @@ -122,7 +122,7 @@ export async function _readFileTree( if (dirEntry.isFile || dirEntry.isSymlink) { const file = new BIDSFileDeno( rootPath, - join(relativePath, dirEntry.name), + posix.join(relativePath, dirEntry.name), ignore, ) // For .bidsignore, read in immediately and add the rules @@ -134,7 +134,7 @@ export async function _readFileTree( if (dirEntry.isDirectory) { const dirTree = await _readFileTree( rootPath, - join(relativePath, dirEntry.name), + posix.join(relativePath, dirEntry.name), ignore, tree, )