aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/os/os_test.go35
-rw-r--r--src/syscall/fs_js.go4
2 files changed, 39 insertions, 0 deletions
diff --git a/src/os/os_test.go b/src/os/os_test.go
index 1d8442d808..cc03b91d72 100644
--- a/src/os/os_test.go
+++ b/src/os/os_test.go
@@ -1242,6 +1242,41 @@ func testChtimes(t *testing.T, name string) {
}
}
+func TestFileChdir(t *testing.T) {
+ // TODO(brainman): file.Chdir() is not implemented on windows.
+ if runtime.GOOS == "windows" {
+ return
+ }
+
+ wd, err := Getwd()
+ if err != nil {
+ t.Fatalf("Getwd: %s", err)
+ }
+ defer Chdir(wd)
+
+ fd, err := Open(".")
+ if err != nil {
+ t.Fatalf("Open .: %s", err)
+ }
+ defer fd.Close()
+
+ if err := Chdir("/"); err != nil {
+ t.Fatalf("Chdir /: %s", err)
+ }
+
+ if err := fd.Chdir(); err != nil {
+ t.Fatalf("fd.Chdir: %s", err)
+ }
+
+ wdNew, err := Getwd()
+ if err != nil {
+ t.Fatalf("Getwd: %s", err)
+ }
+ if wdNew != wd {
+ t.Fatalf("fd.Chdir failed, got %s, want %s", wdNew, wd)
+ }
+}
+
func TestChdirAndGetwd(t *testing.T) {
// TODO(brainman): file.Chdir() is not implemented on windows.
if runtime.GOOS == "windows" {
diff --git a/src/syscall/fs_js.go b/src/syscall/fs_js.go
index c1cac97d91..262ec28afd 100644
--- a/src/syscall/fs_js.go
+++ b/src/syscall/fs_js.go
@@ -102,6 +102,10 @@ func Open(path string, openmode int, perm uint32) (int, error) {
}
}
+ if path[0] != '/' {
+ cwd := jsProcess.Call("cwd").String()
+ path = cwd + "/" + path
+ }
f := &jsFile{
path: path,
entries: entries,