summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Meredith <joshmeredith2008@gmail.com>2023-04-13 16:12:38 +0000
committerJosh Meredith <joshmeredith2008@gmail.com>2023-04-21 17:17:01 +0000
commit8b9132c39a150dae18d93822a6b419543e5bc4a8 (patch)
treeeeefb698fe4dce470bb7449f2ef32ae567162ce3
parentdf1a581188694479a583270548896245fc23b525 (diff)
downloadhaskell-wip/js-mkdir.tar.gz
JS/base: provide implementation for mkdir (issue 22374)wip/js-mkdir
-rw-r--r--libraries/base/jsbits/base.js18
-rw-r--r--libraries/base/tests/IO/all.T4
-rw-r--r--libraries/base/tests/IO/mkdirExists.hs8
-rw-r--r--libraries/base/tests/IO/mkdirExists.stderr1
-rw-r--r--testsuite/tests/ghc-api/target-contents/all.T2
5 files changed, 31 insertions, 2 deletions
diff --git a/libraries/base/jsbits/base.js b/libraries/base/jsbits/base.js
index b9e0b84ce1..1f0123943b 100644
--- a/libraries/base/jsbits/base.js
+++ b/libraries/base/jsbits/base.js
@@ -889,3 +889,21 @@ function h$__hscore_free_dirent(a,o) {
function h$__hscore_d_name(a,o) {
RETURN_UBX_TUP2(h$encodeModifiedUtf8(a.name),0);
}
+
+function h$mkdir(path, path_offset, mode) {
+ if (!h$isNode()) {
+ throw "h$mkdir unsupported";
+ }
+ const d = h$decodeUtf8z(path, path_offset);
+ try {
+ h$fs.mkdirSync(d, {mode: mode});
+ } catch(e) {
+ // we can't directly set errno code, because numbers may not match
+ // e.g. e.errno is -17 for EEXIST while we would expect -20
+ // this is probably an inconsistency between nodejs using the native
+ // environment and everything else using Emscripten-provided headers.
+ h$setErrno(e);
+ return -1;
+ }
+ return 0;
+}
diff --git a/libraries/base/tests/IO/all.T b/libraries/base/tests/IO/all.T
index 92cb93add5..1a54564896 100644
--- a/libraries/base/tests/IO/all.T
+++ b/libraries/base/tests/IO/all.T
@@ -64,7 +64,7 @@ test('misc001', [extra_run_opts('misc001.hs misc001.out')], compile_and_run,
test('openFile001', normal, compile_and_run, [''])
test('openFile002', [exit_code(1), normalise_win32_io_errors], compile_and_run, [''])
-test('openFile003', [normalise_win32_io_errors, js_broken(22374)], compile_and_run, [''])
+test('openFile003', [normalise_win32_io_errors, js_broken(22362)], compile_and_run, [''])
test('openFile004', [], compile_and_run, [''])
test('openFile005', js_broken(22261), compile_and_run, [''])
test('openFile006', [], compile_and_run, [''])
@@ -152,3 +152,5 @@ test('T17510', expect_broken(17510), compile_and_run, [''])
test('bytestringread001', extra_run_opts('test.data'), compile_and_run, [''])
test('T17912', [only_ways(['threaded1']), when(opsys('mingw32'),expect_broken(1))], compile_and_run, [''])
test('T18832', only_ways(['threaded1']), compile_and_run, [''])
+
+test('mkdirExists', [exit_code(1), when(opsys('mingw32'), ignore_stderr)], compile_and_run, [''])
diff --git a/libraries/base/tests/IO/mkdirExists.hs b/libraries/base/tests/IO/mkdirExists.hs
new file mode 100644
index 0000000000..19f5e77f9b
--- /dev/null
+++ b/libraries/base/tests/IO/mkdirExists.hs
@@ -0,0 +1,8 @@
+module Main where
+
+import System.Directory
+
+main :: IO ()
+main = do
+ createDirectory "foo"
+ createDirectory "foo"
diff --git a/libraries/base/tests/IO/mkdirExists.stderr b/libraries/base/tests/IO/mkdirExists.stderr
new file mode 100644
index 0000000000..4d12490fa6
--- /dev/null
+++ b/libraries/base/tests/IO/mkdirExists.stderr
@@ -0,0 +1 @@
+mkdirExists: foo: createDirectory: already exists (File exists)
diff --git a/testsuite/tests/ghc-api/target-contents/all.T b/testsuite/tests/ghc-api/target-contents/all.T
index 684cd06d74..9072d6609e 100644
--- a/testsuite/tests/ghc-api/target-contents/all.T
+++ b/testsuite/tests/ghc-api/target-contents/all.T
@@ -1,6 +1,6 @@
test('TargetContents',
[ extra_run_opts('"' + config.libdir + '"')
- , js_broken(22374)
+ , js_broken(22362)
]
, compile_and_run,
['-package ghc -package exceptions'])