Skip to content

Commit

Permalink
fix: swallow any exceptions when setting file modified timestamp (#1639)
Browse files Browse the repository at this point in the history
Also fixed a situation where setting the cache-evict to "never" would
still cause the cache to be evicted in certain situations.

Fixes #1638
  • Loading branch information
quintesse committed Jun 28, 2023
1 parent c379bd3 commit d81bed7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/dev/jbang/source/ProjectBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public Project build(String resource) {

private ResourceRef resolveChecked(ResourceResolver resolver, String resource) {
Util.verboseMsg("Resolving resource ref: " + resource);
boolean retryCandidate = catalogFile == null && !Util.isFresh() && Settings.getCacheEvict() != 0
boolean retryCandidate = catalogFile == null && !Util.isFresh() && Settings.getCacheEvict() > 0
&& (Catalog.isValidName(resource) || Catalog.isValidCatalogReference(resource)
|| Util.isRemoteRef(resource));
ResourceRef ref = null;
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/dev/jbang/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,18 @@ static ResultHandler handleUnmodified(Path cachedFile, ResultHandler okHandler)
verboseMsg(String.format("Not modified, using cached file %s for remote %s", cachedFile,
conn.getURL().toExternalForm()));
// Update cached file's last modified time
Files.setLastModifiedTime(cachedFile, FileTime.from(ZonedDateTime.now().toInstant()));
try {
Files.setLastModifiedTime(cachedFile, FileTime.from(ZonedDateTime.now().toInstant()));
} catch (IOException e) {
// There is an issue with Java not being able to set the file's last modified
// time
// on certain systems, resulting in an exception. There's not much we can do
// about
// that, so we'll just ignore it. It does mean that files affected by this will
// be
// re-downloaded every time.
verboseMsg("Unable to set last-modified time for " + cachedFile, e);
}
return cachedFile;
}
}
Expand Down

0 comments on commit d81bed7

Please sign in to comment.