From eec9b55dcf8fc08f431f16eaf139ab009453d445 Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Thu, 20 Aug 2020 22:15:11 +0200 Subject: [PATCH] FS: don't cache fallback if running in background If the background job is a little late, the true result might arrive and be cached later. So make sure we don't cache the large fallback resolution in the per-directory cache. Otherwise we'd work with the large fallback until the next restart. Bug: 566170 Change-Id: I7354a6cfddfc0c05144bb0aa41c23029bd4f6af0 Signed-off-by: Thomas Wolf --- org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 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 9c5a1e32d..4d7be0a4c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java @@ -294,6 +294,10 @@ public static FileStoreAttributes get(Path path) { return cached; } FileStoreAttributes attrs = getFileStoreAttributes(dir); + if (attrs == null) { + // Don't cache, result might be late + return FALLBACK_FILESTORE_ATTRIBUTES; + } attrCacheByPath.put(dir, attrs); return attrs; } catch (SecurityException e) { @@ -382,12 +386,16 @@ private static FileStoreAttributes getFileStoreAttributes(Path dir) { }); // even if measuring in background wait a little - if the result // arrives, it's better than returning the large fallback - Optional d = background.get() ? f.get( + boolean runInBackground = background.get(); + Optional d = runInBackground ? f.get( 100, TimeUnit.MILLISECONDS) : f.get(); if (d.isPresent()) { return d.get(); + } else if (runInBackground) { + // return null until measurement is finished + return null; } - // return fallback until measurement is finished + // fall through and return fallback } catch (IOException | InterruptedException | ExecutionException | CancellationException e) { LOG.error(e.getMessage(), e);