summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-12-24 01:10:04 +0100
committerAndreas Kling <kling@serenityos.org>2020-12-24 10:25:18 +0100
commit5bb0bd8c6dbc91342077f9d81f8ce7b9096ddd1c (patch)
treedd253542bd8c451860f3cd5efd99022aa3e34b57 /Userland
parent46a12e32d3b92d75d1c4c678b10421a19763d977 (diff)
downloadserenity-5bb0bd8c6dbc91342077f9d81f8ce7b9096ddd1c.zip
open: Handle file:// URLs properly
open(1) was able to handle most URLs as well as paths, but not file:// URLs (which occur when dragging something from the output of ls, for example). We have to create an URL from the user-supplied argument using create_with_url_or_path(), check whether it's a file:// URL or not and *then* use real_path_for() on the URL's path().
Diffstat (limited to 'Userland')
-rw-r--r--Userland/open.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/Userland/open.cpp b/Userland/open.cpp
index 0e4b4cc5f6..99c2a7e584 100644
--- a/Userland/open.cpp
+++ b/Userland/open.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2020, Sergey Bugaev <bugaevc@serenityos.org>
+ * Copyright (c) 2020, Linus Groh <mail@linusgroh.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -44,18 +45,17 @@ int main(int argc, char* argv[])
bool all_ok = true;
for (auto& url_or_path : urls_or_paths) {
- 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;
- }
+ auto url = URL::create_with_url_or_path(url_or_path);
- URL url = URL::create_with_url_or_path(path);
- if (url.protocol() == "file" && realpath_errno) {
- warnln("Failed to open '{}': {}", url.path(), strerror(realpath_errno));
- all_ok = false;
- continue;
+ if (url.protocol() == "file") {
+ auto real_path = Core::File::real_path_for(url.path());
+ if (real_path.is_null()) {
+ // errno *should* be preserved from Core::File::real_path_for().
+ warnln("Failed to open '{}': {}", url.path(), strerror(errno));
+ all_ok = false;
+ continue;
+ }
+ url = URL::create_with_url_or_path(real_path);
}
if (!Desktop::Launcher::open(url)) {