iTwin / itwinjs-core

Monorepo for iTwin.js Library
https://www.itwinjs.org
MIT License
600 stars 210 forks source link

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

Closed ColinKerr closed 4 months ago

ColinKerr commented 10 months ago

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

pmconne commented 10 months ago

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

ColinKerr commented 10 months ago

Here is an approximate path ... the problem is the way\\?\ is handled \\?\D:\src\app\common\temp\node_modules\.pnpm\@bentley+imodeljs-native@4.2.5\node_modules\@bentley\imodeljs-native\imodeljs-win32-x64\Assets\ECSchemas\Standard

pmconne commented 10 months ago

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.

ColinKerr commented 10 months ago

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