Normalize cache key

This commit is contained in:
Robin Shen 2022-01-20 18:47:48 +08:00
parent cd5d276761
commit f0004e505a
2 changed files with 6 additions and 2 deletions

View File

@ -39,6 +39,10 @@ public class CacheSpec implements Serializable, Validatable {
this.key = key;
}
public String getNormalizedKey() {
return getKey().replaceAll("[^a-zA-Z0-9\\-_\\.]", "-");
}
@Editable(order=200, description="Specify path to cache. Non-absolute path is considered to be relative to job workspace. "
+ "Please note that shell executor only allows non-absolute path here")
@Interpolative(variableSuggester="suggestVariables")

View File

@ -1312,14 +1312,14 @@ public class DefaultJobManager implements JobManager, Runnable, CodePullAuthoriz
for (CacheSpec cacheSpec: jobContext.getCacheSpecs()) {
Optional<CacheInstance> result = sortedInstances
.stream()
.filter(it->it.getCacheKey().equals(cacheSpec.getKey()))
.filter(it->it.getCacheKey().equals(cacheSpec.getNormalizedKey()))
.filter(it->!allAllocated.contains(it.getName()))
.findFirst();
CacheInstance allocation;
if (result.isPresent())
allocation = result.get();
else
allocation = new CacheInstance(UUID.randomUUID().toString(), cacheSpec.getKey());
allocation = new CacheInstance(UUID.randomUUID().toString(), cacheSpec.getNormalizedKey());
allocations.put(allocation, cacheSpec.getPath());
jobContext.getAllocatedCaches().add(allocation.getName());
allAllocated.add(allocation.getName());