Skip to content

Commit

Permalink
Fixes #5740
Browse files Browse the repository at this point in the history
---
 Signed-off-by: Peter Kriens <Peter.Kriens@aQute.biz>

Signed-off-by: Peter Kriens <Peter.Kriens@aQute.biz>
  • Loading branch information
pkriens committed Sep 4, 2023
1 parent 9b1e4cd commit 406301f
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions biz.aQute.bndlib/src/aQute/bnd/osgi/resource/FileResourceCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ SupportingResource getResource(File file, URI uri, Supplier<SupportingResource>
cache.keySet()
.removeIf(key -> (now - key.time) > EXPIRED_DURATION_NANOS);
}
CacheKey cacheKey = new CacheKey(file);
CacheKey cacheKey = new CacheKey(file.toPath(), uri);
SupportingResource resource = cache.computeIfAbsent(cacheKey, key -> create.get());
return resource;
}
Expand All @@ -71,16 +71,14 @@ SupportingResource getResource(File file, URI uri, Supplier<SupportingResource>
* path, size, and last modification time.
*/
static final class CacheKey {
private final Object fileKey;
private final long lastModifiedTime;
private final long size;
final long time;
final Object fileKey;
final URI uri;
final long lastModifiedTime;
final long size;
final long time;

CacheKey(File file) {
this(file.toPath());
}

CacheKey(Path path) {
CacheKey(Path path, URI uri) {
this.uri = uri;
BasicFileAttributes attributes;
try {
attributes = Files.getFileAttributeView(path, BasicFileAttributeView.class)
Expand All @@ -100,26 +98,31 @@ static final class CacheKey {
this.time = System.nanoTime();
}

CacheKey(Path path) {
this(path, null);
}

@Override
public int hashCode() {
return (Objects.hashCode(fileKey) * 31 + Long.hashCode(lastModifiedTime)) * 31 + Long.hashCode(size);
return Objects.hash(fileKey, lastModifiedTime, uri);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
if (this == obj)
return true;
}
if (!(obj instanceof CacheKey other)) {
if (obj == null)
return false;
}
return Objects.equals(fileKey, other.fileKey) && (lastModifiedTime == other.lastModifiedTime)
&& (size == other.size);
if (getClass() != obj.getClass())
return false;
CacheKey other = (CacheKey) obj;
return Objects.equals(fileKey, other.fileKey) && lastModifiedTime == other.lastModifiedTime
&& Objects.equals(uri, other.uri);
}

@Override
public String toString() {
return Objects.toString(fileKey);
return Objects.toString(fileKey) + "-" + Objects.toString(uri);
}
}
}

0 comments on commit 406301f

Please sign in to comment.