Browse Source

DfsGarbageCollector: avoid closing idx and bitmap streams twice

These try-with-resources blocks close the underlying output stream
twice: once when closing the CountingOutputStream wrapper, then again
when closing the DfsOutputStream out.

Simplify by only closing the CountingOutputStream.

In practice this shouldn't matter because the close() method of a
Closable is required to be idempotent, but avoiding the redundant
extra close makes the code simpler to read and understand.

Change-Id: I1778c4fc8ba075a2c6cd2129528bb272cb3a1af7
stable-4.5
Jonathan Nieder 8 years ago
parent
commit
ca2052a8c1
  1. 8
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java

8
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java

@ -485,8 +485,8 @@ public class DfsGarbageCollector {
pack.addFileExt(PACK);
}
try (DfsOutputStream out = objdb.writeFile(pack, INDEX);
CountingOutputStream cnt = new CountingOutputStream(out)) {
try (CountingOutputStream cnt =
new CountingOutputStream(objdb.writeFile(pack, INDEX))) {
pw.writeIndex(cnt);
pack.addFileExt(INDEX);
pack.setFileSize(INDEX, cnt.getCount());
@ -494,8 +494,8 @@ public class DfsGarbageCollector {
}
if (pw.prepareBitmapIndex(pm)) {
try (DfsOutputStream out = objdb.writeFile(pack, BITMAP_INDEX);
CountingOutputStream cnt = new CountingOutputStream(out)) {
try (CountingOutputStream cnt = new CountingOutputStream(
objdb.writeFile(pack, BITMAP_INDEX))) {
pw.writeBitmapIndex(cnt);
pack.addFileExt(BITMAP_INDEX);
pack.setFileSize(BITMAP_INDEX, cnt.getCount());

Loading…
Cancel
Save