Skip to content

Commit 74c3359

Browse files
alimpfardawesomekling
authored andcommitted
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.
1 parent bbad475 commit 74c3359

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Userland/Shell/Builtin.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,10 @@ int Shell::builtin_cd(int argc, const char** argv)
274274
if (cd_history.is_empty() || cd_history.last() != real_path)
275275
cd_history.enqueue(real_path);
276276

277-
const char* path = real_path.characters();
277+
auto path_relative_to_current_directory = LexicalPath::relative_path(real_path, cwd);
278+
if (path_relative_to_current_directory.is_empty())
279+
path_relative_to_current_directory = real_path;
280+
const char* path = path_relative_to_current_directory.characters();
278281

279282
int rc = chdir(path);
280283
if (rc < 0) {
@@ -286,7 +289,7 @@ int Shell::builtin_cd(int argc, const char** argv)
286289
return 1;
287290
}
288291
setenv("OLDPWD", cwd.characters(), 1);
289-
cwd = real_path;
292+
cwd = move(real_path);
290293
setenv("PWD", cwd.characters(), 1);
291294
return 0;
292295
}

0 commit comments

Comments
 (0)