Skip to content

Commit

Permalink
core: avoid adding an invalid cache entry when using an unloaded infra
Browse files Browse the repository at this point in the history
  • Loading branch information
eckter authored and Khoyo committed Jan 18, 2024
1 parent 486129a commit 21b851e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions core/src/main/java/fr/sncf/osrd/api/InfraManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,15 @@ public InfraCacheEntry deleteFromInfraCache(String infraId) {
public FullInfra getInfra(String infraId, String expectedVersion, DiagnosticRecorder diagnosticRecorder)
throws OSRDError, InterruptedException {
try {
infraCache.putIfAbsent(infraId, new InfraCacheEntry());
var cacheEntry = infraCache.get(infraId);
// download the infra for tests
if (loadIfMissing) {
return load(infraId, expectedVersion, diagnosticRecorder);
if (cacheEntry == null || !cacheEntry.status.isStable) {
if (loadIfMissing) {
// download the infra for tests
return load(infraId, expectedVersion, diagnosticRecorder);
} else
throw new OSRDError(ErrorType.InfraNotLoadedException);
}
var obsoleteVersion = expectedVersion != null && !expectedVersion.equals(cacheEntry.version);
if (!cacheEntry.status.isStable)
throw new OSRDError(ErrorType.InfraNotLoadedException);
if (obsoleteVersion) {
deleteFromInfraCache(infraId);
throw new OSRDError(ErrorType.InfraInvalidVersionException);
Expand Down

0 comments on commit 21b851e

Please sign in to comment.