RefDirectory#refreshPathToLooseRef: also refresh loose ref itself We observed that newly generated Gerrit auth tokens weren't visible on all pods in an HA deployment of k8s-gerrit. I debugged resolving loose user refs with core.trustStat = after_open and found that we refresh the attributes of all the directories above a loose ref by opening an inputstream but we don't do this on the loose ref itself. It looks like this could cause the issue we observed. In the example I debugged it was the user ref refs/users/00/10000000 and I found that the attributes of the directories refs/ refs/users/ refs/users/00 were refreshed but the loose ref itself refs/users/00/10000000 was not refreshed. Fix this by also opening the ref's file itself if refreshing its parent directories succeeded. Change-Id: I37aaca2a1f448ca9a1caa325a0c18952cc023121 (cherry picked from commit f23d73e2cf565f3fbafdabbb225b722ba9eacbd4)
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java index 52deac8..c93d176 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
@@ -1297,6 +1297,7 @@ class LooseItems { * path of a loose ref relative to the repository root */ void refreshPathToLooseRef(Path refPath) { + boolean failed = false; for (int i = 1; i < refPath.getNameCount(); i++) { File dir = fileFor(refPath.subpath(0, i).toString()); // Use Files.newInputStream(Path) as it is consistent with other @@ -1305,7 +1306,16 @@ void refreshPathToLooseRef(Path refPath) { try (InputStream stream = Files.newInputStream(dir.toPath())) { // open the dir to refresh attributes (on some NFS clients) } catch (IOException e) { - break; // loose ref may not exist + failed = true; + break; // directory may not exist + } + } + if (!failed) { + try (InputStream stream = Files.newInputStream(refPath)) { + // open the loose ref to refresh attributes (on some NFS + // clients) + } catch (IOException e) { + // loose ref may not exist } } }