diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-08-28 12:06:07 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-28 20:02:27 +0200 |
commit | 74c3359bedc6e4e9c0e69c98dca931bf55c5746b (patch) | |
tree | f0a82a852852972c54ee761c014671a78e98e5ba /Userland/Shell/Builtin.cpp | |
parent | bbad4758b2ca97d29044b593ebb0447bbdbc2c0a (diff) | |
download | serenity-74c3359bedc6e4e9c0e69c98dca931bf55c5746b.zip |
Shell: Use a relative path in builtin_cd for chdir if possible
This kinda sorta addresses the Shell side of #9655, however the fact
that `chdir` (and most other syscalls that take paths) are artifically
limited to a length of PATH_MAX remains.
Diffstat (limited to 'Userland/Shell/Builtin.cpp')
-rw-r--r-- | Userland/Shell/Builtin.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Userland/Shell/Builtin.cpp b/Userland/Shell/Builtin.cpp index 7aab0d120d..afbaa25aff 100644 --- a/Userland/Shell/Builtin.cpp +++ b/Userland/Shell/Builtin.cpp @@ -274,7 +274,10 @@ int Shell::builtin_cd(int argc, const char** argv) if (cd_history.is_empty() || cd_history.last() != real_path) cd_history.enqueue(real_path); - const char* path = real_path.characters(); + auto path_relative_to_current_directory = LexicalPath::relative_path(real_path, cwd); + if (path_relative_to_current_directory.is_empty()) + path_relative_to_current_directory = real_path; + const char* path = path_relative_to_current_directory.characters(); int rc = chdir(path); if (rc < 0) { @@ -286,7 +289,7 @@ int Shell::builtin_cd(int argc, const char** argv) return 1; } setenv("OLDPWD", cwd.characters(), 1); - cwd = real_path; + cwd = move(real_path); setenv("PWD", cwd.characters(), 1); return 0; } |