Skip to content

Remove empty IOException try-catch handling when extracting PostgreSQL binaries #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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