mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 11:45:11 +00:00
LibSQL+Ladybird: Accept a list of paths for spawning SQLServer in Lagom
Use the new get_paths_for_helper_process method in Ladybird to query Qt for the runtime path of the current executable as well as the build directory paths.
This commit is contained in:
parent
3e6d790cf0
commit
ae9dc95b1f
4 changed files with 23 additions and 15 deletions
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "BrowserWindow.h"
|
#include "BrowserWindow.h"
|
||||||
|
#include "HelperProcess.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "Utilities.h"
|
#include "Utilities.h"
|
||||||
#include "WebContentView.h"
|
#include "WebContentView.h"
|
||||||
|
@ -99,7 +100,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto sql_client = TRY(SQL::SQLClient::launch_server_and_create_client("./SQLServer/SQLServer"sv));
|
auto sql_server_paths = TRY(get_paths_for_helper_process("SQLServer"sv));
|
||||||
|
auto sql_client = TRY(SQL::SQLClient::launch_server_and_create_client(move(sql_server_paths)));
|
||||||
auto database = TRY(Browser::Database::create(move(sql_client)));
|
auto database = TRY(Browser::Database::create(move(sql_client)));
|
||||||
|
|
||||||
auto cookie_jar = TRY(Browser::CookieJar::create(*database));
|
auto cookie_jar = TRY(Browser::CookieJar::create(*database));
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/DeprecatedString.h>
|
||||||
|
#include <AK/String.h>
|
||||||
#include <LibSQL/SQLClient.h>
|
#include <LibSQL/SQLClient.h>
|
||||||
|
|
||||||
#if !defined(AK_OS_SERENITY)
|
#if !defined(AK_OS_SERENITY)
|
||||||
|
@ -50,7 +51,7 @@ static ErrorOr<int> create_database_socket(DeprecatedString const& socket_path)
|
||||||
return socket_fd;
|
return socket_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> launch_server(DeprecatedString const& socket_path, DeprecatedString const& pid_path, StringView server_path)
|
static ErrorOr<void> launch_server(DeprecatedString const& socket_path, DeprecatedString const& pid_path, Vector<String> candidate_server_paths)
|
||||||
{
|
{
|
||||||
auto server_fd_or_error = create_database_socket(socket_path);
|
auto server_fd_or_error = create_database_socket(socket_path);
|
||||||
if (server_fd_or_error.is_error()) {
|
if (server_fd_or_error.is_error()) {
|
||||||
|
@ -77,15 +78,19 @@ static ErrorOr<void> launch_server(DeprecatedString const& socket_path, Deprecat
|
||||||
auto takeover_string = DeprecatedString::formatted("SQLServer:{}", server_fd);
|
auto takeover_string = DeprecatedString::formatted("SQLServer:{}", server_fd);
|
||||||
TRY(Core::System::setenv("SOCKET_TAKEOVER"sv, takeover_string, true));
|
TRY(Core::System::setenv("SOCKET_TAKEOVER"sv, takeover_string, true));
|
||||||
|
|
||||||
auto arguments = Array {
|
ErrorOr<void> result;
|
||||||
server_path,
|
for (auto const& server_path : candidate_server_paths) {
|
||||||
"--pid-file"sv,
|
auto arguments = Array {
|
||||||
pid_path,
|
server_path.bytes_as_string_view(),
|
||||||
};
|
"--pid-file"sv,
|
||||||
|
pid_path,
|
||||||
auto result = Core::System::exec(arguments[0], arguments, Core::System::SearchInPath::Yes);
|
};
|
||||||
|
auto result = Core::System::exec(arguments[0], arguments, Core::System::SearchInPath::Yes);
|
||||||
|
if (!result.is_error())
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (result.is_error()) {
|
if (result.is_error()) {
|
||||||
warnln("Could not launch {}: {}", server_path, result.error());
|
warnln("Could not launch any of {}: {}", candidate_server_paths, result.error());
|
||||||
TRY(Core::System::unlink(pid_path));
|
TRY(Core::System::unlink(pid_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,14 +137,14 @@ static ErrorOr<bool> should_launch_server(DeprecatedString const& pid_path)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<NonnullRefPtr<SQLClient>> SQLClient::launch_server_and_create_client(StringView server_path)
|
ErrorOr<NonnullRefPtr<SQLClient>> SQLClient::launch_server_and_create_client(Vector<String> candidate_server_paths)
|
||||||
{
|
{
|
||||||
auto runtime_directory = TRY(Core::StandardPaths::runtime_directory());
|
auto runtime_directory = TRY(Core::StandardPaths::runtime_directory());
|
||||||
auto socket_path = DeprecatedString::formatted("{}/SQLServer.socket", runtime_directory);
|
auto socket_path = DeprecatedString::formatted("{}/SQLServer.socket", runtime_directory);
|
||||||
auto pid_path = DeprecatedString::formatted("{}/SQLServer.pid", runtime_directory);
|
auto pid_path = DeprecatedString::formatted("{}/SQLServer.pid", runtime_directory);
|
||||||
|
|
||||||
if (TRY(should_launch_server(pid_path)))
|
if (TRY(should_launch_server(pid_path)))
|
||||||
TRY(launch_server(socket_path, pid_path, server_path));
|
TRY(launch_server(socket_path, pid_path, move(candidate_server_paths)));
|
||||||
|
|
||||||
auto socket = TRY(Core::Stream::LocalSocket::connect(move(socket_path)));
|
auto socket = TRY(Core::Stream::LocalSocket::connect(move(socket_path)));
|
||||||
TRY(socket->set_blocking(true));
|
TRY(socket->set_blocking(true));
|
||||||
|
|
|
@ -22,7 +22,7 @@ class SQLClient
|
||||||
|
|
||||||
public:
|
public:
|
||||||
#if !defined(AK_OS_SERENITY)
|
#if !defined(AK_OS_SERENITY)
|
||||||
static ErrorOr<NonnullRefPtr<SQLClient>> launch_server_and_create_client(StringView server_path);
|
static ErrorOr<NonnullRefPtr<SQLClient>> launch_server_and_create_client(Vector<String> candidate_server_paths);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
virtual ~SQLClient() = default;
|
virtual ~SQLClient() = default;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/DeprecatedString.h>
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
|
#include <AK/String.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
|
@ -361,8 +362,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
#if defined(AK_OS_SERENITY)
|
#if defined(AK_OS_SERENITY)
|
||||||
auto sql_client = TRY(SQL::SQLClient::try_create());
|
auto sql_client = TRY(SQL::SQLClient::try_create());
|
||||||
#else
|
#else
|
||||||
VERIFY(sql_server_path != nullptr);
|
VERIFY(!sql_server_path.is_empty());
|
||||||
auto sql_client = TRY(SQL::SQLClient::launch_server_and_create_client(sql_server_path));
|
auto sql_client = TRY(SQL::SQLClient::launch_server_and_create_client({ TRY(String::from_utf8(sql_server_path)) }));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SQLRepl repl(loop, database_name, move(sql_client));
|
SQLRepl repl(loop, database_name, move(sql_client));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue