diff --git a/src/main/java/io/jenkins/update_center/ArtifactoryRepositoryImpl.java b/src/main/java/io/jenkins/update_center/ArtifactoryRepositoryImpl.java index bae8fc752..141e92cfd 100644 --- a/src/main/java/io/jenkins/update_center/ArtifactoryRepositoryImpl.java +++ b/src/main/java/io/jenkins/update_center/ArtifactoryRepositoryImpl.java @@ -228,11 +228,18 @@ private InputStream getFileContent(String url) throws IOException { } private File getFile(final String url) throws IOException { + // TODO remove old base64 based cache paths once the cache is migrated String urlBase64 = Base64.encodeBase64String(new URL(url).getPath().getBytes(StandardCharsets.UTF_8)); File cacheFile = new File(cacheDirectory, urlBase64); if (!cacheFile.exists()) { // Preferred new location (guaranteed maximum filename length): - cacheFile = new File(cacheDirectory, DigestUtils.sha256Hex(url)); + final String sha256 = DigestUtils.sha256Hex(url); + final String sha256prefix = sha256.substring(0, 2); // to limit number of files in top-level directory + final File cachePrefixDir = new File(cacheDirectory, sha256prefix); + if (!cachePrefixDir.exists() && !cachePrefixDir.mkdirs()) { + LOGGER.log(Level.WARNING, "Failed to create cache prefix directory " + cachePrefixDir); + } + cacheFile = new File(cachePrefixDir, sha256); } if (!cacheFile.exists()) {