Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Borowitz2018-01-05 18:02:47 +0000
committerDavid Pursehouse2018-06-09 08:34:29 +0000
commit5fe8e31d4351a9d26db81e799defd8225e883f3e (patch)
treeda994127bb1604d6b37cd489d3f486487169baf0
parentdd9a14a762c796080f95f638c5c77b26c3e5fe11 (diff)
downloadjgit-5fe8e31d4351a9d26db81e799defd8225e883f3e.tar.gz
jgit-5fe8e31d4351a9d26db81e799defd8225e883f3e.tar.xz
jgit-5fe8e31d4351a9d26db81e799defd8225e883f3e.zip
Ensure DirectoryStream is closed promptly
From the javadoc for Files.list: "The returned stream encapsulates a DirectoryStream. If timely disposal of file system resources is required, the try-with-resources construct should be used to ensure that the stream's close method is invoked after the stream operations are completed." This is the only call to Files#newDirectoryStream that is not already in a try-with-resources. Change-Id: I91e6c56b5d74e8435457ad6ed9e6b4b24d2aa14e (cherry picked from commit 1c16ea4601920c9dbc7a0202efc20137e1a63d55)
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java26
1 files changed, 13 insertions, 13 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
index 928e52d6b4..60d6652745 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
@@ -966,19 +966,19 @@ public class GC {
Path packDir = Paths.get(repo.getObjectsDirectory().getAbsolutePath(),
"pack"); //$NON-NLS-1$
Instant threshold = Instant.now().minus(1, ChronoUnit.DAYS);
- try {
- Files.newDirectoryStream(packDir, "gc_*_tmp") //$NON-NLS-1$
- .forEach(t -> {
- try {
- Instant lastModified = Files.getLastModifiedTime(t)
- .toInstant();
- if (lastModified.isBefore(threshold)) {
- Files.deleteIfExists(t);
- }
- } catch (IOException e) {
- LOG.error(e.getMessage(), e);
- }
- });
+ try (DirectoryStream<Path> stream =
+ Files.newDirectoryStream(packDir, "gc_*_tmp")) { //$NON-NLS-1$
+ stream.forEach(t -> {
+ try {
+ Instant lastModified = Files.getLastModifiedTime(t)
+ .toInstant();
+ if (lastModified.isBefore(threshold)) {
+ Files.deleteIfExists(t);
+ }
+ } catch (IOException e) {
+ LOG.error(e.getMessage(), e);
+ }
+ });
} catch (IOException e) {
LOG.error(e.getMessage(), e);
}

Back to the top