Shell: Fix how cd handles the path argument

Previously this didn't work:

  $ cd -- /usr
  Invalid path '--'

This path fixes this issue and removes the unnecessary else
branch because we're already using realpath() later on to resolve
relative paths.
This commit is contained in:
Gunnar Beutner 2021-04-23 10:42:16 +02:00 committed by Linus Groh
parent 6a957daba4
commit 1e5a7ca0a7
Notes: sideshowbarker 2024-07-18 19:12:15 +09:00

View File

@ -198,14 +198,8 @@ int Shell::builtin_cd(int argc, const char** argv)
if (oldpwd == nullptr)
return 1;
new_path = oldpwd;
} else if (arg_path[0] == '/') {
new_path = argv[1];
} else {
StringBuilder builder;
builder.append(cwd);
builder.append('/');
builder.append(arg_path);
new_path = builder.to_string();
new_path = arg_path;
}
}