Skip to content

Commit

Permalink
Remove empty IOException try-catch handling when extracting PostgreSQ…
Browse files Browse the repository at this point in the history
…L binaries
  • Loading branch information
Andrey Turbanov committed Sep 6, 2024
1 parent e61945b commit 41b4546
Showing 1 changed file with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ Map<String, String> getConnectConfig()
private static int detectPort() throws IOException
{
try (ServerSocket socket = new ServerSocket(0)) {
while(!socket.isBound()) {
while (!socket.isBound()) {
Thread.sleep(50);
}
return socket.getLocalPort();
Expand Down Expand Up @@ -803,23 +803,19 @@ private static File prepareBinaries(PgBinaryResolver pgBinaryResolver, File over
mkdirs(pgDir);
workingDirectory.setWritable(true, false);

final File unpackLockFile = new File(pgDir, LOCK_FILE_NAME);
final File pgDirExists = new File(pgDir, ".exists");

if (!isPgBinReady(pgDirExists)) {
File unpackLockFile = new File(pgDir, LOCK_FILE_NAME);
try (FileOutputStream lockStream = new FileOutputStream(unpackLockFile);
FileLock unpackLock = lockStream.getChannel().tryLock()) {
if (unpackLock != null) {
try {
LOG.info("Extracting Postgres...");
try (ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray())) {
extractTxz(bais, pgDir);
}
if (!pgDirExists.createNewFile()) {
pgDirExists.setLastModified(System.currentTimeMillis());
}
} catch (Exception e) {
LOG.error("while unpacking Postgres", e);
LOG.info("Extracting Postgres...");
try (ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray())) {
extractTxz(bais, pgDir);
}
if (!pgDirExists.createNewFile()) {
pgDirExists.setLastModified(System.currentTimeMillis());
}
} else {
// the other guy is unpacking for us.
Expand All @@ -838,6 +834,7 @@ private static File prepareBinaries(PgBinaryResolver pgBinaryResolver, File over
}
}
} catch (final IOException | NoSuchAlgorithmException e) {
LOG.error("Got error while unpacking Postgres", e);
throw new ExceptionInInitializerError(e);
} catch (final InterruptedException ie) {
Thread.currentThread().interrupt();
Expand Down

0 comments on commit 41b4546

Please sign in to comment.