fix: properly account for MetaCache mutation when removing old keys

This commit is contained in:
Johannes Frohnmeyer 2024-05-05 15:33:22 +02:00
parent 6dffd405c9
commit 436ef1a966
Signed by: Johannes
GPG Key ID: E76429612C2929F4

View File

@ -68,7 +68,7 @@ public class MetaCache {
Respackopts.LOGGER.warn("Duplicate pack id: {0}", pack.meta().id); Respackopts.LOGGER.warn("Duplicate pack id: {0}", pack.meta().id);
} }
} }
PACK_STATES.keySet().stream().filter(s -> !newKeys.contains(s)).forEach(MetaCache::remove); PACK_STATES.keySet().stream().filter(s -> !newKeys.contains(s)).toList().forEach(MetaCache::remove);
save(SaveHook.Arguments.DO_NOTHING); save(SaveHook.Arguments.DO_NOTHING);
} }
@ -184,20 +184,20 @@ public class MetaCache {
public static Scope getScope(int version) { public static Scope getScope(int version) {
Scope scope = MuScriptScope.fork(version); Scope scope = MuScriptScope.fork(version);
return populate(scope); return populate(scope, null);
} }
public static Scope getScope(@NotNull CacheKey key, RespackoptsFS fs) { public static Scope getScope(@NotNull CacheKey key, RespackoptsFS fs) {
CachedPackState state = MetaCache.getState(key); CachedPackState state = MetaCache.getState(key);
Scope scope = state.executionScope().fork(); Scope scope = state.executionScope().fork();
return populate(MuScriptScope.configureFS(scope, state, fs)); return populate(MuScriptScope.configureFS(scope, state, fs), state);
} }
private static Scope populate(Scope scope) { private static Scope populate(Scope scope, @Nullable CachedPackState pack) {
forEach((id, state) -> { forEach((id, state) -> {
if (!scope.has(state.packId())) { if (scope.has(state.packId())) return;
scope.set(state.packId(), state.configBranch()); if (pack != null && pack.packId().equals(state.packId()) && !pack.equals(state)) return;
} scope.set(state.packId(), state.configBranch());
}); });
return scope; return scope;
} }