Skip to content

Commit

Permalink
FIX: updating PWD system environment variable after each directory …
Browse files Browse the repository at this point in the history
…change

resolves: Oldes/Rebol-issues#2448
  • Loading branch information
Oldes committed Feb 22, 2021
1 parent 9b5723a commit a2b1a40
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
8 changes: 7 additions & 1 deletion src/os/posix/host-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
8 changes: 7 additions & 1 deletion src/os/win32/host-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}


Expand Down
25 changes: 15 additions & 10 deletions src/tests/units/port-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand 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 [
Expand Down

0 comments on commit a2b1a40

Please # to comment.