Hardcode $PWD as read-only for set --show

Through a mechanism I don't entirely understand, $PWD is sometimes
writable (so that `cd` can change it) and sometimes not.

In this case we ended up with it writable, which is wrong.

See #8179.
This commit is contained in:
Fabian Homborg 2021-07-28 22:08:03 +02:00
parent 3db78232c6
commit b3cdf4afe1
2 changed files with 9 additions and 1 deletions

View File

@ -512,7 +512,9 @@ static void show_scope(const wchar_t *var_name, int scope, io_streams_t &streams
wcstring_list_t vals = var->as_list();
streams.out.append_format(_(L"$%ls: set in %ls scope, %ls,%ls with %d elements\n"), var_name,
scope_name, exportv, pathvarv, vals.size());
if (var->read_only()) {
// HACK: PWD can be set, depending on how you ask.
// For our purposes it's read-only.
if (var->read_only() || wcscmp(var_name, L"PWD") == 0) {
streams.out.append(_(L"Variable is read-only\n"));
}

View File

@ -667,6 +667,12 @@ set -S status
#CHECK: Variable is read-only
#CHECK: $status[1]: |0|
# PWD is also read-only.
set -S PWD
#CHECK: $PWD: set in global scope, exported, with 1 elements
#CHECK: Variable is read-only
#CHECK: $PWD[1]: |{{.*}}|
set -ql history
echo $status
#CHECK: 1