Everywhere: Unport Core::System::current_executable_path from new string

Storing paths in AK::String is never correct.
This commit is contained in:
Dan Klishch 2023-11-06 13:49:18 -05:00 committed by Andrew Kaster
parent 610fe28115
commit d317309d89
Notes: sideshowbarker 2024-07-16 22:18:54 +09:00
9 changed files with 12 additions and 12 deletions

View file

@ -25,7 +25,7 @@ ErrorOr<String> find_certificates(StringView serenity_resource_root)
{
auto cert_path = TRY(String::formatted("{}/res/ladybird/cacert.pem", serenity_resource_root));
if (!FileSystem::exists(cert_path)) {
auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path()).to_deprecated_string());
auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path()));
cert_path = TRY(String::formatted("{}/cacert.pem", LexicalPath(app_dir).parent()));
if (!FileSystem::exists(cert_path))

View file

@ -21,7 +21,7 @@ ErrorOr<String> find_certificates(StringView serenity_resource_root)
{
auto cert_path = TRY(String::formatted("{}/res/ladybird/cacert.pem", serenity_resource_root));
if (!FileSystem::exists(cert_path)) {
auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path()).to_deprecated_string());
auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path()));
cert_path = TRY(String::formatted("{}/cacert.pem", LexicalPath(app_dir).parent()));
if (!FileSystem::exists(cert_path))

View file

@ -25,7 +25,7 @@ ErrorOr<String> find_certificates(StringView serenity_resource_root)
{
auto cert_path = TRY(String::formatted("{}/res/ladybird/cacert.pem", serenity_resource_root));
if (!FileSystem::exists(cert_path)) {
auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path()).to_deprecated_string());
auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path()));
cert_path = TRY(String::formatted("{}/cacert.pem", LexicalPath(app_dir).parent()));
if (!FileSystem::exists(cert_path))

View file

@ -17,7 +17,7 @@ DeprecatedString s_serenity_resource_root;
ErrorOr<String> application_directory()
{
auto current_executable_path = TRY(Core::System::current_executable_path());
auto dirname = LexicalPath::dirname(current_executable_path.to_deprecated_string());
auto dirname = LexicalPath::dirname(current_executable_path);
return String::from_deprecated_string(dirname);
}

View file

@ -21,7 +21,7 @@ ErrorOr<String> find_certificates(StringView serenity_resource_root)
{
auto cert_path = TRY(String::formatted("{}/res/ladybird/cacert.pem", serenity_resource_root));
if (!FileSystem::exists(cert_path)) {
auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path()).to_deprecated_string());
auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path()));
cert_path = TRY(String::formatted("{}/cacert.pem", LexicalPath(app_dir).parent()));
if (!FileSystem::exists(cert_path))

View file

@ -1806,7 +1806,7 @@ char** environment()
#endif
}
ErrorOr<String> current_executable_path()
ErrorOr<DeprecatedString> current_executable_path()
{
char path[4096] = {};
#if defined(AK_OS_LINUX) || defined(AK_OS_ANDROID) || defined(AK_OS_SERENITY)
@ -1827,9 +1827,9 @@ ErrorOr<String> current_executable_path()
return Error::from_syscall("proc_get_exe"sv, -errno);
}
#elif defined(AK_OS_DRAGONFLY)
return String::from_deprecated_string(TRY(readlink("/proc/curproc/file"sv)));
return TRY(readlink("/proc/curproc/file"sv));
#elif defined(AK_OS_SOLARIS)
return String::from_deprecated_string(TRY(readlink("/proc/self/path/a.out"sv)));
return TRY(readlink("/proc/self/path/a.out"sv));
#elif defined(AK_OS_FREEBSD)
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
size_t len = sizeof(path);
@ -1862,7 +1862,7 @@ ErrorOr<String> current_executable_path()
return Error::from_string_view("current_executable_path unknown"sv);
#endif
path[sizeof(path) - 1] = '\0';
return String::from_utf8({ path, strlen(path) });
return DeprecatedString { path, strlen(path) };
}
ErrorOr<Bytes> allocate(size_t count, size_t size)

View file

@ -279,7 +279,7 @@ ErrorOr<String> resolve_executable_from_environment(StringView filename, int fla
char** environment();
ErrorOr<String> current_executable_path();
ErrorOr<DeprecatedString> current_executable_path();
ErrorOr<Bytes> allocate(size_t count, size_t size);

View file

@ -18,7 +18,7 @@ namespace {
ErrorOr<String> application_directory()
{
auto current_executable_path = TRY(Core::System::current_executable_path());
auto dirname = LexicalPath::dirname(current_executable_path.to_deprecated_string());
auto dirname = LexicalPath::dirname(current_executable_path);
return String::from_deprecated_string(dirname);
}

View file

@ -224,7 +224,7 @@ static PDF::PDFErrorOr<int> pdf_main(Main::Arguments arguments)
#if !defined(AK_OS_SERENITY)
if (debugging_stats || !render_path.is_empty()) {
// Get from Build/lagom/bin/pdf to Base/res/fonts.
auto source_root = LexicalPath(MUST(Core::System::current_executable_path()).to_deprecated_string()).parent().parent().parent().parent().string();
auto source_root = LexicalPath(MUST(Core::System::current_executable_path())).parent().parent().parent().parent().string();
Core::ResourceImplementation::install(make<Core::ResourceImplementationFile>(TRY(String::formatted("{}/Base/res", source_root))));
}
#endif