From a2b1a408a804cf865cf0078b8723782b27977763 Mon Sep 17 00:00:00 2001 From: Oldes Date: Mon, 22 Feb 2021 11:49:45 +0100 Subject: [PATCH] FIX: updating `PWD` system environment variable after each directory change resolves: https://github.com/Oldes/Rebol-issues/issues/2448 --- src/os/posix/host-lib.c | 8 +++++++- src/os/win32/host-lib.c | 8 +++++++- src/tests/units/port-test.r3 | 25 +++++++++++++++---------- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/os/posix/host-lib.c b/src/os/posix/host-lib.c index d04e880b25..3db8fb2964 100644 --- a/src/os/posix/host-lib.c +++ b/src/os/posix/host-lib.c @@ -653,7 +653,13 @@ int pipe2(int pipefd[2], int flags); //to avoid "implicit-function-declaration" ** ***********************************************************************/ { - return (chdir(path) == 0) ? 0 : errno; + if (chdir(path) == 0) { + // directory changed... update PWD + // https://github.com/Oldes/Rebol-issues/issues/2448 + setenv("PWD", path, 1); + return 0; + } else + return errno; } diff --git a/src/os/win32/host-lib.c b/src/os/win32/host-lib.c index 8d93c04eea..0e93013054 100644 --- a/src/os/win32/host-lib.c +++ b/src/os/win32/host-lib.c @@ -649,7 +649,13 @@ static void *Task_Ready; ** ***********************************************************************/ { - return (SetCurrentDirectory(path[0] == 0 ? L"\\" : path)) ? 0 : GetLastError(); + if (SetCurrentDirectory(path[0] == 0 ? L"\\" : path)) { + // directory changed... update PWD + // https://github.com/Oldes/Rebol-issues/issues/2448 + SetEnvironmentVariable(L"PWD", path); + return 0; + } else + return GetLastError(); } diff --git a/src/tests/units/port-test.r3 b/src/tests/units/port-test.r3 index 51e931d5c1..487ce925bc 100644 --- a/src/tests/units/port-test.r3 +++ b/src/tests/units/port-test.r3 @@ -138,16 +138,6 @@ Rebol [ ;@@ https://github.com/Oldes/Rebol-issues/issues/2447 --assert false? try [delete %not-exists/] --assert error? try [delete %/] - - --test-- "CHANGE-DIR" - ;@@ https://github.com/Oldes/Rebol-issues/issues/2446 - --assert what-dir = change-dir %. - --assert all [ - error? e: try [change-dir %issues/2446] - e/id = 'cannot-open - e/arg1 = join what-dir %issues/2446/ - ] - if system/platform = 'Windows [ ;@@ it looks that on Linux there is no lock on opened file --assert all [ @@ -169,6 +159,21 @@ if system/platform = 'Windows [ ] ] + --test-- "CHANGE-DIR" + ;@@ https://github.com/Oldes/Rebol-issues/issues/2446 + --assert what-dir = change-dir %. + --assert all [ + error? e: try [change-dir %issues/2446] + e/id = 'cannot-open + e/arg1 = join what-dir %issues/2446/ + ] + ;@@ https://github.com/Oldes/Rebol-issues/issues/2448 + dir: pwd + --assert pwd = to-rebol-file get-env "PWD" + change-dir %../ + --assert pwd = to-rebol-file get-env "PWD" + change-dir dir + --test-- "RENAME dir" ;@@ https://github.com/Oldes/Rebol-issues/issues/1533 --assert all [