Skip to content

Commit a2b1a40

Browse files
committed
FIX: updating PWD system environment variable after each directory change
resolves: Oldes/Rebol-issues#2448
1 parent 9b5723a commit a2b1a40

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

src/os/posix/host-lib.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,13 @@ int pipe2(int pipefd[2], int flags); //to avoid "implicit-function-declaration"
653653
**
654654
***********************************************************************/
655655
{
656-
return (chdir(path) == 0) ? 0 : errno;
656+
if (chdir(path) == 0) {
657+
// directory changed... update PWD
658+
// https://github.com/Oldes/Rebol-issues/issues/2448
659+
setenv("PWD", path, 1);
660+
return 0;
661+
} else
662+
return errno;
657663
}
658664

659665

src/os/win32/host-lib.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,13 @@ static void *Task_Ready;
649649
**
650650
***********************************************************************/
651651
{
652-
return (SetCurrentDirectory(path[0] == 0 ? L"\\" : path)) ? 0 : GetLastError();
652+
if (SetCurrentDirectory(path[0] == 0 ? L"\\" : path)) {
653+
// directory changed... update PWD
654+
// https://github.com/Oldes/Rebol-issues/issues/2448
655+
SetEnvironmentVariable(L"PWD", path);
656+
return 0;
657+
} else
658+
return GetLastError();
653659
}
654660

655661

src/tests/units/port-test.r3

+15-10
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,6 @@ Rebol [
138138
;@@ https://github.com/Oldes/Rebol-issues/issues/2447
139139
--assert false? try [delete %not-exists/]
140140
--assert error? try [delete %/]
141-
142-
--test-- "CHANGE-DIR"
143-
;@@ https://github.com/Oldes/Rebol-issues/issues/2446
144-
--assert what-dir = change-dir %.
145-
--assert all [
146-
error? e: try [change-dir %issues/2446]
147-
e/id = 'cannot-open
148-
e/arg1 = join what-dir %issues/2446/
149-
]
150-
151141
if system/platform = 'Windows [
152142
;@@ it looks that on Linux there is no lock on opened file
153143
--assert all [
@@ -169,6 +159,21 @@ if system/platform = 'Windows [
169159
]
170160
]
171161

162+
--test-- "CHANGE-DIR"
163+
;@@ https://github.com/Oldes/Rebol-issues/issues/2446
164+
--assert what-dir = change-dir %.
165+
--assert all [
166+
error? e: try [change-dir %issues/2446]
167+
e/id = 'cannot-open
168+
e/arg1 = join what-dir %issues/2446/
169+
]
170+
;@@ https://github.com/Oldes/Rebol-issues/issues/2448
171+
dir: pwd
172+
--assert pwd = to-rebol-file get-env "PWD"
173+
change-dir %../
174+
--assert pwd = to-rebol-file get-env "PWD"
175+
change-dir dir
176+
172177
--test-- "RENAME dir"
173178
;@@ https://github.com/Oldes/Rebol-issues/issues/1533
174179
--assert all [

0 commit comments

Comments
 (0)