itwinjs-core icon indicating copy to clipboard operation
itwinjs-core copied to clipboard

KnownLocations.nativeAssetsDir returns a path not compatible with the SchemaXmlFileLocater on Windows

Open ColinKerr opened this issue 2 years ago • 4 comments

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

ColinKerr avatar Oct 26 '23 17:10 ColinKerr

Please provide the actual path name returned on your machine by KnownLocations.nativeAssetsDir. I assume it is not actually "banana".

pmconne avatar Oct 26 '23 19:10 pmconne

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

ColinKerr avatar Oct 26 '23 19:10 ColinKerr

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.

pmconne avatar Oct 26 '23 19:10 pmconne

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

ColinKerr avatar Oct 26 '23 20:10 ColinKerr