mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
fs: key glob matcher cache by platform
Glob matchers capture the path platform when they are created. Include the platform in the cache key so path.posix and path.win32 do not share incompatible matchers for the same pattern. Signed-off-by: Archkon <180910180+Archkon@users.noreply.github.com> PR-URL: https://github.com/nodejs/node/pull/64571 Fixes: https://github.com/nodejs/node/issues/64570 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
This commit is contained in:
1 parent
9f9a96030d
commit
12f7fc0558
2 files changed
+7
-3
No files matched your search
@@ -936,15 +936,16 @@ function matchGlobPattern(path, pattern, windows = isWindows) {
|
||||
validateString(path, 'path');
|
||||
validateString(pattern, 'pattern');
|
||||
|
||||
const cacheKey = `${windows ? 'win32' : 'posix'}:${pattern}`;
|
||||
let matcher;
|
||||
if (patternFnCache.has(pattern)) {
|
||||
matcher = patternFnCache.get(pattern);
|
||||
if (patternFnCache.has(cacheKey)) {
|
||||
matcher = patternFnCache.get(cacheKey);
|
||||
} else {
|
||||
matcher = createMatcher(pattern, {
|
||||
kEmptyObject,
|
||||
platform: windows ? 'win32' : 'posix',
|
||||
});
|
||||
patternFnCache.set(pattern, matcher);
|
||||
patternFnCache.set(cacheKey, matcher);
|
||||
|
||||
if (patternFnCache.size >= kGlobPatternCacheLimit) {
|
||||
patternFnCache.delete(patternFnCache.keys().next().value);
|
||||
|
||||
@@ -31,6 +31,9 @@ const globs = {
|
||||
],
|
||||
};
|
||||
|
||||
// Matchers for the same pattern must not be shared across path platforms.
|
||||
assert.strictEqual(path.posix.matchesGlob('platform-cache/file', 'platform-cache/**'), true);
|
||||
assert.strictEqual(path.win32.matchesGlob('platform-cache\\file', 'platform-cache/**'), true);
|
||||
|
||||
for (const [platform, platformGlobs] of Object.entries(globs)) {
|
||||
for (const [pathStr, glob, expected] of platformGlobs) {
|
||||
|
||||
Reference in new issue
Block a user