diff options
author | Linus Groh <mail@linusgroh.de> | 2021-03-07 17:14:58 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-07 17:39:58 +0100 |
commit | 3532e1788f22d6db1a5c26d7fef28bd391c2f4a0 (patch) | |
tree | 3ad8b5de0119bbdf7196668cbc3fc3c16383e3a8 /Userland/Utilities/open.cpp | |
parent | 501952852ce84606618b82b703dedd505a11357a (diff) | |
download | serenity-3532e1788f22d6db1a5c26d7fef28bd391c2f4a0.zip |
open: Fix opening "." (again)
We can't always rely on the initial URL's path(), so use either the
user-specified argument or the URL path for determining the realpath,
depending on whether we got a file:// URL argument.
Fixes #4950.
Diffstat (limited to 'Userland/Utilities/open.cpp')
-rw-r--r-- | Userland/Utilities/open.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Userland/Utilities/open.cpp b/Userland/Utilities/open.cpp index c141eb817f..10e7491343 100644 --- a/Userland/Utilities/open.cpp +++ b/Userland/Utilities/open.cpp @@ -48,7 +48,10 @@ int main(int argc, char* argv[]) auto url = URL::create_with_url_or_path(url_or_path); if (url.protocol() == "file") { - auto real_path = Core::File::real_path_for(url.path()); + // NOTE: Since URL::create_with_url_or_path() returns "file:///" for ".", and we chose + // to fix that in open(1) itself using Core::File::real_path_for(), we have to + // conditionally chose either the URL's path or user-specified argument (also a path). + auto real_path = Core::File::real_path_for(StringView(url_or_path).starts_with("file://") ? url.path() : url_or_path); if (real_path.is_null()) { // errno *should* be preserved from Core::File::real_path_for(). warnln("Failed to open '{}': {}", url.path(), strerror(errno)); |