Skip to content

Commit

Permalink
fix tmpFile closing
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgeniiMunin committed Jan 16, 2025
1 parent 9794643 commit a7cbc33
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ private Future<DatabaseReader> downloadAndExtract() {
private Future<Void> downloadFile(String downloadUrl, String tmpPath) {
return fileSystem.open(tmpPath, new OpenOptions())
.compose(tmpFile -> sendHttpRequest(downloadUrl)
.compose(response -> response.pipeTo(tmpFile))
.onFailure(error -> logger.error(
"Failed to download file from {} to {}.", downloadUrl, tmpPath, error)));
.onFailure(ignore -> tmpFile.close())
.compose(response -> response.pipeTo(tmpFile)));
}

private Future<HttpClientResponse> sendHttpRequest(String url) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ private Future<Boolean> isSizeChanged() {
private Future<Void> downloadFile() {
return fileSystem.open(tmpPath, new OpenOptions())
.compose(tmpFile -> sendHttpRequest(getRequestOptions)
.onFailure(ignore -> tmpFile.close())
.compose(response -> response.pipeTo(tmpFile))
.onComplete(result -> tmpFile.close()));
}
Expand Down

0 comments on commit a7cbc33

Please sign in to comment.