Skip to content

Commit

Permalink
Fixed #987 - File Handle Leaks in DataDiff and TempRDBMS (#988)
Browse files Browse the repository at this point in the history
* Fixed #987 - File Handle Leaks in DataDiff and TempRDBMS

* FIXED #897 - clean up formatting

* Fixed #987 Clean Up Formatting

Co-authored-by: gregwilmer <gwilmer@petco.com>
  • Loading branch information
gwilmer and gregwilmer authored Oct 18, 2021
1 parent 8dea889 commit 89b5a85
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Types;
import java.util.ArrayList;
Expand All @@ -34,6 +35,7 @@
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Stream;

import org.apache.commons.io.FileUtils;
import org.h2.Driver;
Expand Down Expand Up @@ -299,12 +301,11 @@ protected void calculateDiff(ISendMessageCallback callback) {
ds.close();

if (!inMemoryCompare) {
try {
Files.list(Paths.get(System.getProperty("h2.baseDir")))
.filter(path -> path.toFile().getName().startsWith(databaseName))
.forEach(path -> deleteDatabaseFile(path.toFile()));
try (Stream<Path> stream = Files.list(Paths.get(System.getProperty("h2.baseDir")))) {
stream.filter(path -> path.toFile().getName().startsWith(databaseName))
.forEach(path -> deleteDatabaseFile(path.toFile()));
} catch (IOException e) {
log.warn("Failed to delete file", e);
log.warn("Failed to delete file", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Types;
import java.util.List;
import java.util.UUID;
import java.util.stream.Stream;

import javax.sql.DataSource;

Expand Down Expand Up @@ -134,9 +136,9 @@ protected void query(ISendMessageCallback callback) {
ds.close();

if (!inMemoryDb) {
try {
Files.list(Paths.get(System.getProperty("h2.baseDir"))).filter(path -> path.toFile().getName().startsWith(databaseName))
.forEach(path -> deleteDatabaseFile(path.toFile()));
try (Stream<Path> stream = Files.list(Paths.get(System.getProperty("h2.baseDir")))) {
stream.filter(path -> path.toFile().getName().startsWith(databaseName))
.forEach(path -> deleteDatabaseFile(path.toFile()));
} catch (IOException e) {
log.warn("Failed to delete file", e);
}
Expand Down

0 comments on commit 89b5a85

Please sign in to comment.