itwinjs-core
itwinjs-core copied to clipboard
KnownLocations.nativeAssetsDir returns a path not compatible with the SchemaXmlFileLocater on Windows
Describe the bug
This method returns a path prefixed with \?\ like \\?\C:\banana\. This seems to interfere with glob.GlobSync used to match candidate schema files
To Reproduce Run this test on windows:
it.only("locate core custom attributes", async () => {
await IModelHost.startup();
const cont = new SchemaContext();
const loc = new SchemaXmlFileLocater();
cont.addLocater(loc);
loc.addSchemaSearchPath(path.join(KnownLocations.nativeAssetsDir, "ECSchemas", "Standard"));
const schemaKey = new SchemaKey("Units", 1, 0, 0);
const schema = await cont.getSchema(schemaKey, SchemaMatchType.Latest);
assert.isDefined(schema);
assert.strictEqual(schema?.name, "Units");
await IModelHost.shutdown();
});
NOTE: If you strip the first 4 characters of the string returned by nativeAssetsDir the test works
Expected behavior The Units schema should be loaded correctly
- OS: Windows
- Version: 11
- iTwin.js Version: 4.x tip
Please provide the actual path name returned on your machine by KnownLocations.nativeAssetsDir. I assume it is not actually "banana".
Here is an approximate path ... the problem is the way\\?\ is handled
\\?\D:\src\app\common\temp\node_modules\.pnpm\@[email protected]\node_modules\@bentley\imodeljs-native\imodeljs-win32-x64\Assets\ECSchemas\Standard
Right - thanks. Do you consider that an "us" problem (i.e., we need to somehow escape that valid path before passing it to GlobSync), or a GlobSync problem (i.e., it's not properly handling valid paths)?
Stripping off the \\?\ won't suffice; without it, the path length is limited to MAX_PATH.
Further investigation is needed to determine if there is something we can do or if there is a bug in glob. If there is a bug in glob we will have to report it and put a temporary work around in place until it is fixed