Skip to content

Commit

Permalink
Even tighter check
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmitterdorfer committed Jul 17, 2023
1 parent a67f281 commit 9d3d546
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,13 @@ public ProfilingIndex withGeneration(String generation) {
}

public boolean isMatchWithoutVersion(String indexName) {
return indexName.startsWith("." + namePrefix + "-v");
String expectedPrefix = "." + namePrefix + "-v";
return indexName.startsWith(expectedPrefix) && isVersionNumber(indexName, expectedPrefix.length());
}

private boolean isVersionNumber(String name, int startIndex) {
final int versionNumberLength = 3;
return name.substring(startIndex, startIndex + versionNumberLength).chars().allMatch(Character::isDigit);
}

public boolean isMatchWithoutGeneration(String indexName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public void testIndexMatchWithoutVersion() {
ProfilingIndexManager.ProfilingIndex idx = ProfilingIndexManager.ProfilingIndex.kv("profiling-test", 1);
assertTrue(idx.isMatchWithoutVersion(".profiling-test-v002"));
assertFalse(idx.isMatchWithoutVersion(".profiling-testing-v001"));
assertFalse(idx.isMatchWithoutVersion(".profiling-test-verbose"));
}

private ActionResponse verifyIndexInstalled(
Expand Down

0 comments on commit 9d3d546

Please sign in to comment.