summaryrefslogtreecommitdiff
path: root/Userland/open.cpp
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-08-08 14:16:44 +0430
committerAndreas Kling <kling@serenityos.org>2020-08-08 11:58:57 +0200
commit7ebba7bf3c880e7a98c39ca83f34aa9703a6f922 (patch)
tree3783f126131b38533a5d80f1d8aa18e73602ac86 /Userland/open.cpp
parent62ec42c1126e1e2e4402a95631ac9f2ee567e5a7 (diff)
downloadserenity-7ebba7bf3c880e7a98c39ca83f34aa9703a6f922.zip
open: Resolve the realpath before passing it to URL()
...which runs it through LexicalPath. Fixes #3016.
Diffstat (limited to 'Userland/open.cpp')
-rw-r--r--Userland/open.cpp24
1 files changed, 14 insertions, 10 deletions
diff --git a/Userland/open.cpp b/Userland/open.cpp
index 11588bad0d..3af6620c5b 100644
--- a/Userland/open.cpp
+++ b/Userland/open.cpp
@@ -28,6 +28,7 @@
#include <AK/Vector.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/EventLoop.h>
+#include <LibCore/File.h>
#include <LibDesktop/Launcher.h>
#include <string.h>
@@ -42,17 +43,20 @@ int main(int argc, char* argv[])
bool all_ok = true;
for (auto& url_or_path : urls_or_paths) {
- URL url = URL::create_with_url_or_path(url_or_path);
- if (url.protocol() == "file" && !url.path().starts_with('/')) {
- if (auto* path = realpath(url.path().characters(), nullptr)) {
- url.set_path(path);
- free(path);
- } else {
- fprintf(stderr, "Failed to open '%s': %s\n", url.path().characters(), strerror(errno));
- all_ok = false;
- continue;
- }
+ String path;
+ auto realpath_errno = 0;
+ if (path = Core::File::real_path_for(url_or_path); path.is_null()) {
+ realpath_errno = errno; // This *should* be preserved from Core::File::real_path_for().
+ path = url_or_path;
}
+
+ URL url = URL::create_with_url_or_path(path);
+ if (url.protocol() == "file" && realpath_errno) {
+ fprintf(stderr, "Failed to open '%s': %s\n", url.path().characters(), strerror(realpath_errno));
+ all_ok = false;
+ continue;
+ }
+
if (!Desktop::Launcher::open(url)) {
fprintf(stderr, "Failed to open '%s'\n", url.path().characters());
all_ok = false;