mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:52:45 +00:00 
			
		
		
		
	Ladybird+Userland: Use ByteString for candidate server paths
We've adopted a stance that paths should be ByteStrings rather than UTF-8 strings, so apply that to the Ladybird helpers.
This commit is contained in:
		
							parent
							
								
									1e0dd9aa8c
								
							
						
					
					
						commit
						0a55749a39
					
				
					 10 changed files with 30 additions and 31 deletions
				
			
		|  | @ -8,7 +8,7 @@ | |||
| 
 | ||||
| ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process( | ||||
|     WebView::ViewImplementation& view, | ||||
|     ReadonlySpan<String> candidate_web_content_paths, | ||||
|     ReadonlySpan<ByteString> candidate_web_content_paths, | ||||
|     Ladybird::WebContentOptions const& web_content_options) | ||||
| { | ||||
|     int socket_fds[2] {}; | ||||
|  | @ -43,7 +43,7 @@ ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process( | |||
|                 "valgrind"sv, | ||||
|                 "--tool=callgrind"sv, | ||||
|                 "--instr-atstart=no"sv, | ||||
|                 path.bytes_as_string_view(), | ||||
|                 path.view(), | ||||
|                 "--command-line"sv, | ||||
|                 web_content_options.command_line, | ||||
|                 "--executable-path"sv, | ||||
|  | @ -97,7 +97,7 @@ ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process( | |||
| } | ||||
| 
 | ||||
| template<typename Client> | ||||
| ErrorOr<NonnullRefPtr<Client>> launch_generic_server_process(ReadonlySpan<String> candidate_server_paths, StringView serenity_resource_root, Vector<ByteString> const& certificates, StringView server_name) | ||||
| ErrorOr<NonnullRefPtr<Client>> launch_generic_server_process(ReadonlySpan<ByteString> candidate_server_paths, StringView serenity_resource_root, Vector<ByteString> const& certificates, StringView server_name) | ||||
| { | ||||
|     int socket_fds[2] {}; | ||||
|     TRY(Core::System::socketpair(AF_LOCAL, SOCK_STREAM, 0, socket_fds)); | ||||
|  | @ -127,7 +127,7 @@ ErrorOr<NonnullRefPtr<Client>> launch_generic_server_process(ReadonlySpan<String | |||
|                 continue; | ||||
| 
 | ||||
|             auto arguments = Vector<StringView, 5> { | ||||
|                 path.bytes_as_string_view(), | ||||
|                 path.view(), | ||||
|                 "--fd-passing-socket"sv, | ||||
|                 fd_passing_socket_string, | ||||
|             }; | ||||
|  | @ -163,22 +163,22 @@ ErrorOr<NonnullRefPtr<Client>> launch_generic_server_process(ReadonlySpan<String | |||
|     return new_client; | ||||
| } | ||||
| 
 | ||||
| ErrorOr<NonnullRefPtr<ImageDecoderClient::Client>> launch_image_decoder_process(ReadonlySpan<String> candidate_image_decoder_paths) | ||||
| ErrorOr<NonnullRefPtr<ImageDecoderClient::Client>> launch_image_decoder_process(ReadonlySpan<ByteString> candidate_image_decoder_paths) | ||||
| { | ||||
|     return launch_generic_server_process<ImageDecoderClient::Client>(candidate_image_decoder_paths, ""sv, {}, "ImageDecoder"sv); | ||||
| } | ||||
| 
 | ||||
| ErrorOr<NonnullRefPtr<Web::HTML::WebWorkerClient>> launch_web_worker_process(ReadonlySpan<String> candidate_web_worker_paths, Vector<ByteString> const& certificates) | ||||
| ErrorOr<NonnullRefPtr<Web::HTML::WebWorkerClient>> launch_web_worker_process(ReadonlySpan<ByteString> candidate_web_worker_paths, Vector<ByteString> const& certificates) | ||||
| { | ||||
|     return launch_generic_server_process<Web::HTML::WebWorkerClient>(candidate_web_worker_paths, ""sv, certificates, "WebWorker"sv); | ||||
| } | ||||
| 
 | ||||
| ErrorOr<NonnullRefPtr<Protocol::RequestClient>> launch_request_server_process(ReadonlySpan<String> candidate_request_server_paths, StringView serenity_resource_root, Vector<ByteString> const& certificates) | ||||
| ErrorOr<NonnullRefPtr<Protocol::RequestClient>> launch_request_server_process(ReadonlySpan<ByteString> candidate_request_server_paths, StringView serenity_resource_root, Vector<ByteString> const& certificates) | ||||
| { | ||||
|     return launch_generic_server_process<Protocol::RequestClient>(candidate_request_server_paths, serenity_resource_root, certificates, "RequestServer"sv); | ||||
| } | ||||
| 
 | ||||
| ErrorOr<NonnullRefPtr<Protocol::WebSocketClient>> launch_web_socket_process(ReadonlySpan<String> candidate_web_socket_paths, StringView serenity_resource_root, Vector<ByteString> const& certificates) | ||||
| ErrorOr<NonnullRefPtr<Protocol::WebSocketClient>> launch_web_socket_process(ReadonlySpan<ByteString> candidate_web_socket_paths, StringView serenity_resource_root, Vector<ByteString> const& certificates) | ||||
| { | ||||
|     return launch_generic_server_process<Protocol::WebSocketClient>(candidate_web_socket_paths, serenity_resource_root, certificates, "WebSocket"sv); | ||||
| } | ||||
|  |  | |||
|  | @ -19,10 +19,10 @@ | |||
| 
 | ||||
| ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process( | ||||
|     WebView::ViewImplementation& view, | ||||
|     ReadonlySpan<String> candidate_web_content_paths, | ||||
|     ReadonlySpan<ByteString> candidate_web_content_paths, | ||||
|     Ladybird::WebContentOptions const&); | ||||
| 
 | ||||
| ErrorOr<NonnullRefPtr<ImageDecoderClient::Client>> launch_image_decoder_process(ReadonlySpan<String> candidate_image_decoder_paths); | ||||
| ErrorOr<NonnullRefPtr<Web::HTML::WebWorkerClient>> launch_web_worker_process(ReadonlySpan<String> candidate_web_worker_paths, Vector<ByteString> const& certificates); | ||||
| ErrorOr<NonnullRefPtr<Protocol::RequestClient>> launch_request_server_process(ReadonlySpan<String> candidate_request_server_paths, StringView serenity_resource_root, Vector<ByteString> const& certificates); | ||||
| ErrorOr<NonnullRefPtr<Protocol::WebSocketClient>> launch_web_socket_process(ReadonlySpan<String> candidate_web_socket_paths, StringView serenity_resource_root, Vector<ByteString> const& certificates); | ||||
| ErrorOr<NonnullRefPtr<ImageDecoderClient::Client>> launch_image_decoder_process(ReadonlySpan<ByteString> candidate_image_decoder_paths); | ||||
| ErrorOr<NonnullRefPtr<Web::HTML::WebWorkerClient>> launch_web_worker_process(ReadonlySpan<ByteString> candidate_web_worker_paths, Vector<ByteString> const& certificates); | ||||
| ErrorOr<NonnullRefPtr<Protocol::RequestClient>> launch_request_server_process(ReadonlySpan<ByteString> candidate_request_server_paths, StringView serenity_resource_root, Vector<ByteString> const& certificates); | ||||
| ErrorOr<NonnullRefPtr<Protocol::WebSocketClient>> launch_web_socket_process(ReadonlySpan<ByteString> candidate_web_socket_paths, StringView serenity_resource_root, Vector<ByteString> const& certificates); | ||||
|  |  | |||
|  | @ -14,11 +14,10 @@ | |||
| 
 | ||||
| ByteString s_serenity_resource_root; | ||||
| 
 | ||||
| ErrorOr<String> application_directory() | ||||
| ErrorOr<ByteString> application_directory() | ||||
| { | ||||
|     auto current_executable_path = TRY(Core::System::current_executable_path()); | ||||
|     auto dirname = LexicalPath::dirname(current_executable_path); | ||||
|     return String::from_byte_string(dirname); | ||||
|     return LexicalPath::dirname(current_executable_path); | ||||
| } | ||||
| 
 | ||||
| void platform_init() | ||||
|  | @ -33,7 +32,7 @@ void platform_init() | |||
|         auto home_lagom = ByteString::formatted("{}/.lagom", home); | ||||
|         if (FileSystem::is_directory(home_lagom)) | ||||
|             return home_lagom; | ||||
|         auto app_dir = application_directory().release_value_but_fixme_should_propagate_errors().to_byte_string(); | ||||
|         auto app_dir = MUST(application_directory()); | ||||
| #ifdef AK_OS_MACOS | ||||
|         return LexicalPath(app_dir).parent().append("Resources"sv).string(); | ||||
| #else | ||||
|  | @ -44,13 +43,13 @@ void platform_init() | |||
|     Core::ResourceImplementation::install(make<Core::ResourceImplementationFile>(MUST(String::formatted("{}/res", s_serenity_resource_root)))); | ||||
| } | ||||
| 
 | ||||
| ErrorOr<Vector<String>> get_paths_for_helper_process(StringView process_name) | ||||
| ErrorOr<Vector<ByteString>> get_paths_for_helper_process(StringView process_name) | ||||
| { | ||||
|     auto application_path = TRY(application_directory()); | ||||
|     Vector<String> paths; | ||||
|     Vector<ByteString> paths; | ||||
| 
 | ||||
|     TRY(paths.try_append(TRY(String::formatted("{}/{}", application_path, process_name)))); | ||||
|     TRY(paths.try_append(TRY(String::formatted("./{}", process_name)))); | ||||
|     TRY(paths.try_append(ByteString::formatted("{}/{}", application_path, process_name))); | ||||
|     TRY(paths.try_append(ByteString::formatted("./{}", process_name))); | ||||
|     // NOTE: Add platform-specific paths here
 | ||||
|     return paths; | ||||
| } | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ | |||
| #include <AK/Vector.h> | ||||
| 
 | ||||
| void platform_init(); | ||||
| ErrorOr<String> application_directory(); | ||||
| ErrorOr<Vector<String>> get_paths_for_helper_process(StringView process_name); | ||||
| ErrorOr<ByteString> application_directory(); | ||||
| ErrorOr<Vector<ByteString>> get_paths_for_helper_process(StringView process_name); | ||||
| 
 | ||||
| extern ByteString s_serenity_resource_root; | ||||
|  |  | |||
|  | @ -24,7 +24,7 @@ static ErrorOr<pid_t> launch_process(StringView application, ReadonlySpan<char c | |||
| 
 | ||||
|     ErrorOr<pid_t> result = -1; | ||||
|     for (auto const& path : paths) { | ||||
|         auto path_view = path.bytes_as_string_view(); | ||||
|         auto path_view = path.view(); | ||||
|         result = Core::Process::spawn(path_view, arguments, {}, Core::Process::KeepAsChild::Yes); | ||||
|         if (!result.is_error()) | ||||
|             break; | ||||
|  |  | |||
|  | @ -52,7 +52,7 @@ static ErrorOr<int> create_database_socket(ByteString const& socket_path) | |||
|     return socket_fd; | ||||
| } | ||||
| 
 | ||||
| static ErrorOr<void> launch_server(ByteString const& socket_path, ByteString const& pid_path, Vector<String> candidate_server_paths) | ||||
| static ErrorOr<void> launch_server(ByteString const& socket_path, ByteString const& pid_path, Vector<ByteString> candidate_server_paths) | ||||
| { | ||||
|     auto server_fd_or_error = create_database_socket(socket_path); | ||||
|     if (server_fd_or_error.is_error()) { | ||||
|  | @ -87,7 +87,7 @@ static ErrorOr<void> launch_server(ByteString const& socket_path, ByteString con | |||
|         ErrorOr<void> result; | ||||
|         for (auto const& server_path : candidate_server_paths) { | ||||
|             auto arguments = Array { | ||||
|                 server_path.bytes_as_string_view(), | ||||
|                 server_path.view(), | ||||
|                 "--pid-file"sv, | ||||
|                 pid_path, | ||||
|             }; | ||||
|  | @ -147,7 +147,7 @@ static ErrorOr<bool> should_launch_server(ByteString const& pid_path) | |||
|     return false; | ||||
| } | ||||
| 
 | ||||
| ErrorOr<NonnullRefPtr<SQLClient>> SQLClient::launch_server_and_create_client(Vector<String> candidate_server_paths) | ||||
| ErrorOr<NonnullRefPtr<SQLClient>> SQLClient::launch_server_and_create_client(Vector<ByteString> candidate_server_paths) | ||||
| { | ||||
|     auto runtime_directory = TRY(Core::StandardPaths::runtime_directory()); | ||||
|     auto socket_path = ByteString::formatted("{}/SQLServer.socket", runtime_directory); | ||||
|  |  | |||
|  | @ -55,7 +55,7 @@ class SQLClient | |||
| 
 | ||||
| public: | ||||
| #if !defined(AK_OS_SERENITY) | ||||
|     static ErrorOr<NonnullRefPtr<SQLClient>> launch_server_and_create_client(Vector<String> candidate_server_paths); | ||||
|     static ErrorOr<NonnullRefPtr<SQLClient>> launch_server_and_create_client(Vector<ByteString> candidate_server_paths); | ||||
| #endif | ||||
| 
 | ||||
|     virtual ~SQLClient() = default; | ||||
|  |  | |||
|  | @ -19,7 +19,7 @@ ErrorOr<NonnullRefPtr<Database>> Database::create() | |||
| 
 | ||||
| #if !defined(AK_OS_SERENITY) | ||||
| 
 | ||||
| ErrorOr<NonnullRefPtr<Database>> Database::create(Vector<String> candidate_sql_server_paths) | ||||
| ErrorOr<NonnullRefPtr<Database>> Database::create(Vector<ByteString> candidate_sql_server_paths) | ||||
| { | ||||
|     auto sql_client = TRY(SQL::SQLClient::launch_server_and_create_client(move(candidate_sql_server_paths))); | ||||
|     return create(move(sql_client)); | ||||
|  |  | |||
|  | @ -30,7 +30,7 @@ class Database : public RefCounted<Database> { | |||
| public: | ||||
|     static ErrorOr<NonnullRefPtr<Database>> create(); | ||||
| #if !defined(AK_OS_SERENITY) | ||||
|     static ErrorOr<NonnullRefPtr<Database>> create(Vector<String> candidate_sql_server_paths); | ||||
|     static ErrorOr<NonnullRefPtr<Database>> create(Vector<ByteString> candidate_sql_server_paths); | ||||
| #endif | ||||
| 
 | ||||
|     ErrorOr<SQL::StatementID> prepare_statement(StringView statement); | ||||
|  |  | |||
|  | @ -360,7 +360,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | |||
|     auto sql_client = TRY(SQL::SQLClient::try_create()); | ||||
| #else | ||||
|     VERIFY(!sql_server_path.is_empty()); | ||||
|     auto sql_client = TRY(SQL::SQLClient::launch_server_and_create_client({ TRY(String::from_utf8(sql_server_path)) })); | ||||
|     auto sql_client = TRY(SQL::SQLClient::launch_server_and_create_client({ sql_server_path })); | ||||
| #endif | ||||
| 
 | ||||
|     SQLRepl repl(loop, database_name, move(sql_client)); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andrew Kaster
						Andrew Kaster