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
This commit is contained in:
Jonathan Nieder 2016-07-07 16:08:02 -07:00
parent 450c0af42f
commit ca2052a8c1
1 changed files with 4 additions and 4 deletions

View File

@ -485,8 +485,8 @@ private DfsPackDescription writePack(PackSource source, PackWriter pw,
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 @@ private DfsPackDescription writePack(PackSource source, PackWriter pw,
}
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());