Skip to content

Commit

Permalink
Remove hostname from cache key (#613)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Beck <[email protected]>
  • Loading branch information
daniel-beck and daniel-beck authored Jun 27, 2022
1 parent 95235d6 commit b634b9a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,12 @@ 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));
final String path = new URL(url).getPath();
String urlBase64 = Base64.encodeBase64String(path.getBytes(StandardCharsets.UTF_8));
File cacheFile = new File(cacheDirectory, urlBase64);
if (!cacheFile.exists()) {
// Preferred new location (guaranteed maximum filename length):
final String sha256 = DigestUtils.sha256Hex(url);
final String sha256 = DigestUtils.sha256Hex(path);
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()) {
Expand All @@ -244,7 +245,7 @@ private File getFile(final String url) throws IOException {

if (!cacheFile.exists()) {
// High log level, but during regular operation this will indicate when an artifact is newly picked up, so useful to know.
LOGGER.log(Level.INFO, "Downloading : " + url + " (not found in cache)");
LOGGER.log(Level.INFO, "Downloading : " + url + " (not found in cache) to " + cacheFile.getName());

final File parentFile = cacheFile.getParentFile();
if (!parentFile.mkdirs() && !parentFile.isDirectory()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void update() throws IOException {
try {
return v.getRequiredJenkinsVersion();
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to determine required Jenkins version for " + v.getGavId());
LOGGER.log(Level.WARNING, "Failed to determine required Jenkins version for " + v.getGavId(), e);
return null;
}
}).filter(Objects::nonNull).collect(Collectors.toSet()).stream().map(VersionNumber::new).sorted(Comparator.reverseOrder()).collect(Collectors.toList());
Expand Down

0 comments on commit b634b9a

Please sign in to comment.