mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:07: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:
parent
bbad4758b2
commit
74c3359bed
1 changed files with 5 additions and 2 deletions
|
@ -274,7 +274,10 @@ int Shell::builtin_cd(int argc, const char** argv)
|
||||||
if (cd_history.is_empty() || cd_history.last() != real_path)
|
if (cd_history.is_empty() || cd_history.last() != real_path)
|
||||||
cd_history.enqueue(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);
|
int rc = chdir(path);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
|
@ -286,7 +289,7 @@ int Shell::builtin_cd(int argc, const char** argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
setenv("OLDPWD", cwd.characters(), 1);
|
setenv("OLDPWD", cwd.characters(), 1);
|
||||||
cwd = real_path;
|
cwd = move(real_path);
|
||||||
setenv("PWD", cwd.characters(), 1);
|
setenv("PWD", cwd.characters(), 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue