diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2025-03-27 00:57:43 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2025-05-21 10:11:35 +0000 |
commit | 98494cd1aea545970dba1b782ca764c9edd58fda (patch) | |
tree | 6e42bd16a3b61295f754681b72b6d7b5edd2e459 | |
parent | ca665a4f07dfefca75ff6702174ff35b35373a8f (diff) | |
download | jgit-98494cd1aea545970dba1b782ca764c9edd58fda.tar.gz jgit-98494cd1aea545970dba1b782ca764c9edd58fda.zip |
FS.getFileStoreAttributes: cancel failed task executed asynchronously
to avoid unnecessary computations if the task getting
FileStoreAttributes asynchronously timed out, cancelled or failed with
another exceptions.
Change-Id: I127a3e2f3710fc5a8742c61f513576ee2d84baed
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java index 59bbacfa76..6a40fad1db 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java @@ -363,6 +363,7 @@ public abstract class FS { private static FileStoreAttributes getFileStoreAttributes(Path dir) { FileStore s; + CompletableFuture<Optional<FileStoreAttributes>> f = null; try { if (Files.exists(dir)) { s = Files.getFileStore(dir); @@ -385,7 +386,7 @@ public abstract class FS { return FALLBACK_FILESTORE_ATTRIBUTES; } - CompletableFuture<Optional<FileStoreAttributes>> f = CompletableFuture + f = CompletableFuture .supplyAsync(() -> { Lock lock = locks.computeIfAbsent(s, l -> new ReentrantLock()); @@ -455,10 +456,13 @@ public abstract class FS { } // fall through and return fallback } catch (IOException | ExecutionException | CancellationException e) { + cancel(f); LOG.error(e.getMessage(), e); } catch (TimeoutException | SecurityException e) { + cancel(f); // use fallback } catch (InterruptedException e) { + cancel(f); LOG.error(e.getMessage(), e); Thread.currentThread().interrupt(); } @@ -467,6 +471,13 @@ public abstract class FS { return FALLBACK_FILESTORE_ATTRIBUTES; } + private static void cancel( + CompletableFuture<Optional<FileStoreAttributes>> f) { + if (f != null) { + f.cancel(true); + } + } + @SuppressWarnings("boxing") private static Duration measureMinimalRacyInterval(Path dir) { LOG.debug("{}: start measure minimal racy interval in {}", //$NON-NLS-1$ |