Skip to content
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