Skip to content

Commit

Permalink
LaunchServer: Resolve symlinks when querying for handler application
Browse files Browse the repository at this point in the history
This lets us launch proper handler application for symlinks :^)
  • Loading branch information
luk1337 authored and alimpfard committed Aug 10, 2021
1 parent 51d559e commit 31d659d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Userland/Services/LaunchServer/Launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <AK/LexicalPath.h>
#include <AK/StringBuilder.h>
#include <LibCore/ConfigFile.h>
#include <LibCore/File.h>
#include <LibDesktop/AppFile.h>
#include <errno.h>
#include <serenity.h>
Expand Down Expand Up @@ -252,8 +253,8 @@ void Launcher::for_each_handler(const String& key, HashMap<String, String>& user
void Launcher::for_each_handler_for_path(const String& path, Function<bool(const Handler&)> f)
{
struct stat st;
if (stat(path.characters(), &st) < 0) {
perror("stat");
if (lstat(path.characters(), &st) < 0) {
perror("lstat");
return;
}

Expand All @@ -269,6 +270,13 @@ void Launcher::for_each_handler_for_path(const String& path, Function<bool(const
if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode))
return;

if (S_ISLNK(st.st_mode)) {
auto real_path = Core::File::real_path_for(String::formatted("{}/{}", LexicalPath::dirname(path), Core::File::read_link(path)));
return for_each_handler_for_path(real_path, [&](const auto& handler) -> bool {
return f(handler);
});
}

if ((st.st_mode & S_IFMT) == S_IFREG && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
f(get_handler_for_executable(Handler::Type::Application, path));

Expand Down

0 comments on commit 31d659d

Please sign in to comment.