1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:27:35 +00:00

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.
This commit is contained in:
Ali Mohammad Pur 2021-08-28 12:06:07 +04:30 committed by Andreas Kling
parent bbad4758b2
commit 74c3359bed

View file

@ -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;
}