realpath: Use physical PWD

This was an inadvertent change from
cc632d6ae9.

Because we used wgetcwd directly before, we always got the "physical"
resolved $PWD.

There's an argument to be made to use the logical $PWD here as well
but I prefer not to make changes lik that in a random commit without
good reason.
This commit is contained in:
Fabian Boehm 2022-07-18 20:45:30 +02:00
parent 5dfb64b547
commit 407a455cfd
2 changed files with 20 additions and 1 deletions

View file

@ -101,7 +101,13 @@ maybe_t<int> builtin_realpath(parser_t &parser, io_streams_t &streams, const wch
return STATUS_CMD_ERROR;
}
} else {
wcstring absolute_arg = string_prefixes_string(L"/", arg) ? arg : path_apply_working_directory(arg, parser.vars().get_pwd_slash());
// We need to get the *physical* pwd here.
auto realpwd = wrealpath(parser.vars().get_pwd_slash());
if (!realpwd) {
streams.err.append_format(L"builtin %ls: realpath failed: %s\n", cmd, std::strerror(errno));
return STATUS_CMD_ERROR;
}
wcstring absolute_arg = string_prefixes_string(L"/", arg) ? arg : path_apply_working_directory(arg, *realpwd);
streams.out.append(normalize_path(absolute_arg, /* allow leading double slashes */ false));
}

View file

@ -72,6 +72,19 @@ else
echo "fish-symlink not handled correctly: $real_path != $expected_real_path" >&2
end
# But the $PWD is still resolved
set -l oldpwd $PWD
cd $XDG_DATA_HOME/fish-symlink
set -l real_path (builtin realpath -s $data_home_realpath/fish-symlink)
set -l expected_real_path "$data_home_realpath/fish-symlink"
if test "$real_path" = "$expected_real_path"
echo "fish-symlink handled correctly"
# CHECK: fish-symlink handled correctly
else
echo "fish-symlink not handled correctly: $real_path != $expected_real_path" >&2
end
cd $oldpwd
set -l real_path (builtin realpath -s .)
set -l expected_real_path (pwd -P) # Physical working directory.
if test "$real_path" = "$expected_real_path"