@shd101wyy/yo 0.0.26 → 0.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -6
- package/out/cjs/index.cjs +568 -563
- package/out/cjs/yo-cli.cjs +686 -556
- package/out/esm/index.mjs +509 -504
- package/out/types/src/build-runner.d.ts +22 -0
- package/out/types/src/cache.d.ts +3 -0
- package/out/types/src/codegen/async/state-machine.d.ts +1 -1
- package/out/types/src/codegen/codegen-c.d.ts +3 -0
- package/out/types/src/codegen/exprs/await.d.ts +1 -0
- package/out/types/src/codegen/exprs/return.d.ts +1 -0
- package/out/types/src/codegen/exprs/while.d.ts +1 -1
- package/out/types/src/codegen/functions/context.d.ts +6 -18
- package/out/types/src/codegen/functions/declarations.d.ts +10 -2
- package/out/types/src/codegen/index.d.ts +4 -0
- package/out/types/src/codegen/utils/index.d.ts +3 -0
- package/out/types/src/evaluator/async/await-analysis.d.ts +1 -0
- package/out/types/src/evaluator/builtins/build.d.ts +135 -0
- package/out/types/src/evaluator/context.d.ts +1 -0
- package/out/types/src/expr.d.ts +18 -0
- package/out/types/src/fetch-command.d.ts +6 -0
- package/out/types/src/fetch.d.ts +10 -0
- package/out/types/src/function-value.d.ts +1 -0
- package/out/types/src/init.d.ts +5 -0
- package/out/types/src/install-command.d.ts +6 -0
- package/out/types/src/lock-file.d.ts +16 -0
- package/out/types/src/module-manager.d.ts +3 -1
- package/out/types/src/pkg-config.d.ts +11 -0
- package/out/types/src/target.d.ts +28 -0
- package/out/types/src/tests/build-system.test.d.ts +1 -0
- package/out/types/src/types/creators.d.ts +2 -1
- package/out/types/src/types/definitions.d.ts +2 -1
- package/out/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/std/build.yo +287 -0
- package/std/crypto/random.yo +27 -15
- package/std/encoding/base64.yo +24 -49
- package/std/encoding/hex.yo +25 -22
- package/std/encoding/json.yo +25 -3
- package/std/encoding/utf16.yo +6 -5
- package/std/fs/dir.yo +107 -104
- package/std/fs/file.yo +122 -158
- package/std/fs/metadata.yo +23 -22
- package/std/fs/temp.yo +42 -48
- package/std/fs/walker.yo +48 -55
- package/std/net/addr.yo +8 -7
- package/std/net/dns.yo +27 -33
- package/std/net/errors.yo +13 -8
- package/std/net/tcp.yo +92 -113
- package/std/net/udp.yo +50 -54
- package/std/os/env.yo +5 -5
- package/std/os/signal.yo +21 -16
- package/std/path.yo +2 -2
- package/std/prelude.yo +23 -2
- package/std/process.yo +23 -43
- package/std/sys/clock.yo +1 -1
- package/std/sys/constants.yo +3 -3
- package/std/sys/errors.yo +45 -33
- package/std/sys/mmap.yo +2 -2
- package/std/sys/signals.yo +4 -4
- package/std/sys/socket.yo +25 -25
- package/std/sys/sysinfo.yo +4 -4
- package/std/url/url.yo +19 -32
- package/out/types/src/codegen/effects/effect-state-machine.d.ts +0 -34
package/std/encoding/utf16.yo
CHANGED
|
@@ -6,11 +6,12 @@
|
|
|
6
6
|
// { utf8_to_utf16, utf16_to_utf8 } :: import "std/encoding/utf16";
|
|
7
7
|
//
|
|
8
8
|
// words := utf8_to_utf16("hello");
|
|
9
|
-
// s := utf16_to_utf8(words)
|
|
9
|
+
// s := utf16_to_utf8(words);
|
|
10
10
|
|
|
11
11
|
open import "../string";
|
|
12
12
|
{ ArrayList } :: import "../collections/array_list";
|
|
13
13
|
{ EncodingError } :: import "./hex";
|
|
14
|
+
{ Error, AnyError, Exception } :: import "../error";
|
|
14
15
|
|
|
15
16
|
// ============================================================================
|
|
16
17
|
// UTF-8 → UTF-16
|
|
@@ -63,7 +64,7 @@ export utf8_to_utf16;
|
|
|
63
64
|
// UTF-16 → UTF-8
|
|
64
65
|
// ============================================================================
|
|
65
66
|
|
|
66
|
-
utf16_to_utf8 :: (fn(data: ArrayList(u16)) ->
|
|
67
|
+
utf16_to_utf8 :: (fn(data: ArrayList(u16), using(exn : Exception)) -> String)({
|
|
67
68
|
out := ArrayList(u8).new();
|
|
68
69
|
i := usize(0);
|
|
69
70
|
while (i < data.len()), {
|
|
@@ -73,14 +74,14 @@ utf16_to_utf8 :: (fn(data: ArrayList(u16)) -> Result(String, EncodingError))({
|
|
|
73
74
|
((w >= u32(0xD800)) && (w <= u32(0xDBFF))) => {
|
|
74
75
|
cond(
|
|
75
76
|
((i + usize(1)) >= data.len()) => {
|
|
76
|
-
|
|
77
|
+
exn.throw(dyn EncodingError.InvalidChar(u8(0)));
|
|
77
78
|
},
|
|
78
79
|
true => ()
|
|
79
80
|
);
|
|
80
81
|
w2 := u32(data.get((i + usize(1))).unwrap());
|
|
81
82
|
cond(
|
|
82
83
|
((w2 < u32(0xDC00)) || (w2 > u32(0xDFFF))) => {
|
|
83
|
-
|
|
84
|
+
exn.throw(dyn EncodingError.InvalidChar(u8(0)));
|
|
84
85
|
},
|
|
85
86
|
true => ()
|
|
86
87
|
);
|
|
@@ -109,7 +110,7 @@ utf16_to_utf8 :: (fn(data: ArrayList(u16)) -> Result(String, EncodingError))({
|
|
|
109
110
|
}
|
|
110
111
|
);
|
|
111
112
|
};
|
|
112
|
-
|
|
113
|
+
String.from_bytes(out)
|
|
113
114
|
});
|
|
114
115
|
|
|
115
116
|
export utf16_to_utf8;
|
package/std/fs/dir.yo
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
// std/fs/dir.yo - High-level directory operations
|
|
2
2
|
//
|
|
3
|
-
// Wraps low-level std/sys/dir with typed APIs using
|
|
3
|
+
// Wraps low-level std/sys/dir with typed APIs using Exception effect.
|
|
4
4
|
//
|
|
5
5
|
// Example:
|
|
6
6
|
// { create_dir, remove_dir, read_dir } :: import "std/fs/dir";
|
|
7
7
|
// { Path } :: import "std/path";
|
|
8
8
|
//
|
|
9
9
|
// main :: (fn(using(io : IO)) -> unit)({
|
|
10
|
+
// given(exn) : Exception = {
|
|
11
|
+
// throw : (fn(forall(T : Type), error: AnyError) -> T)(
|
|
12
|
+
// { println(error.to_string()); exit(i32(1)); }
|
|
13
|
+
// )
|
|
14
|
+
// };
|
|
15
|
+
//
|
|
10
16
|
// io.await(create_dir(Path.new(`/tmp/yo_test`)));
|
|
11
17
|
// entries := io.await(read_dir(Path.new(`/tmp/yo_test`)));
|
|
12
18
|
// io.await(remove_dir(Path.new(`/tmp/yo_test`)));
|
|
@@ -18,6 +24,7 @@
|
|
|
18
24
|
open import "../string";
|
|
19
25
|
{ Path } :: import "../path";
|
|
20
26
|
{ IOError } :: import "../sys/errors";
|
|
27
|
+
{ Error, AnyError, Exception } :: import "../error";
|
|
21
28
|
IO_dir :: import "../sys/dir";
|
|
22
29
|
IO_file :: import "../sys/file";
|
|
23
30
|
{ platform, Platform } :: import "../process";
|
|
@@ -57,39 +64,39 @@ export DirEntry;
|
|
|
57
64
|
// ============================================================================
|
|
58
65
|
|
|
59
66
|
// Create a directory at the given path.
|
|
60
|
-
create_dir :: (fn(path: Path, using(io : IO)) -> Impl(Future(
|
|
61
|
-
io.async((using(io
|
|
67
|
+
create_dir :: (fn(path: Path, using(io : IO)) -> Impl(Future(unit, IO, Exception)))(
|
|
68
|
+
io.async((using(io, exn)) => {
|
|
62
69
|
cstr_bytes := path.to_string().to_cstr();
|
|
63
70
|
cstr := cstr_bytes.ptr().unwrap();
|
|
64
71
|
result := io.await(IO_dir.mkdir(AT_FDCWD, cstr, i32(DEFAULT_DIR_MODE)));
|
|
65
72
|
cond(
|
|
66
|
-
(result < i32(0)) => .
|
|
67
|
-
true =>
|
|
73
|
+
(result < i32(0)) => exn.throw(dyn IOError.from_errno((i32(0) - result))),
|
|
74
|
+
true => ()
|
|
68
75
|
)
|
|
69
76
|
})
|
|
70
77
|
);
|
|
71
78
|
|
|
72
79
|
// Create a directory (str version).
|
|
73
|
-
create_dir_str :: (fn(path: str, using(io : IO)) -> Impl(Future(
|
|
74
|
-
create_dir(Path.new(String.from(path))
|
|
80
|
+
create_dir_str :: (fn(path: str, using(io : IO)) -> Impl(Future(unit, IO, Exception)))(
|
|
81
|
+
create_dir(Path.new(String.from(path)))
|
|
75
82
|
);
|
|
76
83
|
|
|
77
84
|
// Create a directory and all parent directories.
|
|
78
85
|
// Does not error if the directory already exists.
|
|
79
|
-
create_dir_all :: (fn(path: Path, using(io : IO)) -> Impl(Future(
|
|
80
|
-
io.async((using(io
|
|
86
|
+
create_dir_all :: (fn(path: Path, using(io : IO)) -> Impl(Future(unit, IO, Exception)))(
|
|
87
|
+
io.async((using(io, exn)) => {
|
|
81
88
|
path_s := path.to_string();
|
|
82
89
|
cstr_bytes := path_s.to_cstr();
|
|
83
90
|
cstr := cstr_bytes.ptr().unwrap();
|
|
84
91
|
// Try creating the directory directly first
|
|
85
92
|
result := io.await(IO_dir.mkdir(AT_FDCWD, cstr, i32(DEFAULT_DIR_MODE)));
|
|
86
93
|
cond(
|
|
87
|
-
(result >= i32(0)) =>
|
|
94
|
+
(result >= i32(0)) => (),
|
|
88
95
|
true => {
|
|
89
96
|
errno := (i32(0) - result);
|
|
90
97
|
cond(
|
|
91
98
|
// Already exists is OK
|
|
92
|
-
(errno == i32(17)) =>
|
|
99
|
+
(errno == i32(17)) => (),
|
|
93
100
|
// ENOENT - try to create parents
|
|
94
101
|
(errno == i32(2)) => {
|
|
95
102
|
// Walk the path and create each component
|
|
@@ -98,7 +105,7 @@ create_dir_all :: (fn(path: Path, using(io : IO)) -> Impl(Future(Result(unit, IO
|
|
|
98
105
|
// On Windows, skip past drive letter root (e.g., "C:\")
|
|
99
106
|
// to avoid trying to mkdir "C:" which fails with EACCES
|
|
100
107
|
cond(
|
|
101
|
-
(platform == Platform.
|
|
108
|
+
(platform == Platform.Windows) => {
|
|
102
109
|
cond(
|
|
103
110
|
(bytes.len() >= usize(3)) => {
|
|
104
111
|
first := bytes.get(usize(0)).unwrap();
|
|
@@ -123,8 +130,7 @@ create_dir_all :: (fn(path: Path, using(io : IO)) -> Impl(Future(Result(unit, IO
|
|
|
123
130
|
// Ignore EEXIST errors
|
|
124
131
|
cond(
|
|
125
132
|
((r < i32(0)) && ((i32(0) - r) != i32(17))) => {
|
|
126
|
-
(
|
|
127
|
-
return ret;
|
|
133
|
+
exn.throw(dyn IOError.from_errno((i32(0) - r)));
|
|
128
134
|
},
|
|
129
135
|
true => ()
|
|
130
136
|
);
|
|
@@ -136,17 +142,17 @@ create_dir_all :: (fn(path: Path, using(io : IO)) -> Impl(Future(Result(unit, IO
|
|
|
136
142
|
// Create the final directory
|
|
137
143
|
final_result := io.await(IO_dir.mkdir(AT_FDCWD, cstr, i32(DEFAULT_DIR_MODE)));
|
|
138
144
|
cond(
|
|
139
|
-
(final_result >= i32(0)) =>
|
|
145
|
+
(final_result >= i32(0)) => (),
|
|
140
146
|
true => {
|
|
141
147
|
final_errno := (i32(0) - final_result);
|
|
142
148
|
cond(
|
|
143
|
-
(final_errno == i32(17)) =>
|
|
144
|
-
true => .
|
|
149
|
+
(final_errno == i32(17)) => (),
|
|
150
|
+
true => exn.throw(dyn IOError.from_errno(final_errno))
|
|
145
151
|
)
|
|
146
152
|
}
|
|
147
153
|
)
|
|
148
154
|
},
|
|
149
|
-
true => .
|
|
155
|
+
true => exn.throw(dyn IOError.from_errno(errno))
|
|
150
156
|
)
|
|
151
157
|
}
|
|
152
158
|
)
|
|
@@ -154,99 +160,99 @@ create_dir_all :: (fn(path: Path, using(io : IO)) -> Impl(Future(Result(unit, IO
|
|
|
154
160
|
);
|
|
155
161
|
|
|
156
162
|
// Create a directory and all parents (str version).
|
|
157
|
-
create_dir_all_str :: (fn(path: str, using(io : IO)) -> Impl(Future(
|
|
158
|
-
create_dir_all(Path.new(String.from(path))
|
|
163
|
+
create_dir_all_str :: (fn(path: str, using(io : IO)) -> Impl(Future(unit, IO, Exception)))(
|
|
164
|
+
create_dir_all(Path.new(String.from(path)))
|
|
159
165
|
);
|
|
160
166
|
|
|
161
167
|
// Remove an empty directory.
|
|
162
|
-
remove_dir :: (fn(path: Path, using(io : IO)) -> Impl(Future(
|
|
163
|
-
io.async((using(io
|
|
168
|
+
remove_dir :: (fn(path: Path, using(io : IO)) -> Impl(Future(unit, IO, Exception)))(
|
|
169
|
+
io.async((using(io, exn)) => {
|
|
164
170
|
cstr_bytes := path.to_string().to_cstr();
|
|
165
171
|
cstr := cstr_bytes.ptr().unwrap();
|
|
166
172
|
result := io.await(IO_dir.unlink(AT_FDCWD, cstr, AT_REMOVEDIR));
|
|
167
173
|
cond(
|
|
168
|
-
(result < i32(0)) => .
|
|
169
|
-
true =>
|
|
174
|
+
(result < i32(0)) => exn.throw(dyn IOError.from_errno((i32(0) - result))),
|
|
175
|
+
true => ()
|
|
170
176
|
)
|
|
171
177
|
})
|
|
172
178
|
);
|
|
173
179
|
|
|
174
|
-
remove_dir_str :: (fn(path: str, using(io : IO)) -> Impl(Future(
|
|
175
|
-
remove_dir(Path.new(String.from(path))
|
|
180
|
+
remove_dir_str :: (fn(path: str, using(io : IO)) -> Impl(Future(unit, IO, Exception)))(
|
|
181
|
+
remove_dir(Path.new(String.from(path)))
|
|
176
182
|
);
|
|
177
183
|
|
|
178
184
|
// Remove a file.
|
|
179
|
-
remove_file :: (fn(path: Path, using(io : IO)) -> Impl(Future(
|
|
180
|
-
io.async((using(io
|
|
185
|
+
remove_file :: (fn(path: Path, using(io : IO)) -> Impl(Future(unit, IO, Exception)))(
|
|
186
|
+
io.async((using(io, exn)) => {
|
|
181
187
|
cstr_bytes := path.to_string().to_cstr();
|
|
182
188
|
cstr := cstr_bytes.ptr().unwrap();
|
|
183
189
|
result := io.await(IO_dir.unlink(AT_FDCWD, cstr, i32(0)));
|
|
184
190
|
cond(
|
|
185
|
-
(result < i32(0)) => .
|
|
186
|
-
true =>
|
|
191
|
+
(result < i32(0)) => exn.throw(dyn IOError.from_errno((i32(0) - result))),
|
|
192
|
+
true => ()
|
|
187
193
|
)
|
|
188
194
|
})
|
|
189
195
|
);
|
|
190
196
|
|
|
191
|
-
remove_file_str :: (fn(path: str, using(io : IO)) -> Impl(Future(
|
|
192
|
-
remove_file(Path.new(String.from(path))
|
|
197
|
+
remove_file_str :: (fn(path: str, using(io : IO)) -> Impl(Future(unit, IO, Exception)))
|
|
198
|
+
remove_file(Path.new(String.from(path)))
|
|
193
199
|
;
|
|
194
200
|
|
|
195
201
|
// Rename/move a file or directory.
|
|
196
|
-
rename :: (fn(from: Path, to: Path, using(io : IO)) -> Impl(Future(
|
|
197
|
-
io.async((using(io
|
|
202
|
+
rename :: (fn(from: Path, to: Path, using(io : IO)) -> Impl(Future(unit, IO, Exception)))(
|
|
203
|
+
io.async((using(io, exn)) => {
|
|
198
204
|
from_cstr_bytes := from.to_string().to_cstr();
|
|
199
205
|
from_cstr := from_cstr_bytes.ptr().unwrap();
|
|
200
206
|
to_cstr_bytes := to.to_string().to_cstr();
|
|
201
207
|
to_cstr := to_cstr_bytes.ptr().unwrap();
|
|
202
208
|
result := io.await(IO_dir.rename(AT_FDCWD, from_cstr, AT_FDCWD, to_cstr));
|
|
203
209
|
cond(
|
|
204
|
-
(result < i32(0)) => .
|
|
205
|
-
true =>
|
|
210
|
+
(result < i32(0)) => exn.throw(dyn IOError.from_errno((i32(0) - result))),
|
|
211
|
+
true => ()
|
|
206
212
|
)
|
|
207
213
|
})
|
|
208
214
|
);
|
|
209
215
|
|
|
210
|
-
rename_str :: (fn(from: str, to: str, using(io : IO)) -> Impl(Future(
|
|
211
|
-
rename(Path.new(String.from(from)), Path.new(String.from(to))
|
|
216
|
+
rename_str :: (fn(from: str, to: str, using(io : IO)) -> Impl(Future(unit, IO, Exception)))
|
|
217
|
+
rename(Path.new(String.from(from)), Path.new(String.from(to)))
|
|
212
218
|
;
|
|
213
219
|
|
|
214
220
|
// Create a hard link from src to dst.
|
|
215
|
-
hard_link :: (fn(src: Path, dst: Path, using(io : IO)) -> Impl(Future(
|
|
216
|
-
io.async((using(io
|
|
221
|
+
hard_link :: (fn(src: Path, dst: Path, using(io : IO)) -> Impl(Future(unit, IO, Exception)))(
|
|
222
|
+
io.async((using(io, exn)) => {
|
|
217
223
|
src_cstr_bytes := src.to_string().to_cstr();
|
|
218
224
|
src_cstr := src_cstr_bytes.ptr().unwrap();
|
|
219
225
|
dst_cstr_bytes := dst.to_string().to_cstr();
|
|
220
226
|
dst_cstr := dst_cstr_bytes.ptr().unwrap();
|
|
221
227
|
result := io.await(IO_dir.link(AT_FDCWD, src_cstr, AT_FDCWD, dst_cstr, i32(0)));
|
|
222
228
|
cond(
|
|
223
|
-
(result < i32(0)) => .
|
|
224
|
-
true =>
|
|
229
|
+
(result < i32(0)) => exn.throw(dyn IOError.from_errno((i32(0) - result))),
|
|
230
|
+
true => ()
|
|
225
231
|
)
|
|
226
232
|
})
|
|
227
233
|
);
|
|
228
234
|
|
|
229
|
-
hard_link_str :: (fn(src: str, dst: str, using(io : IO)) -> Impl(Future(
|
|
230
|
-
hard_link(Path.new(String.from(src)), Path.new(String.from(dst))
|
|
235
|
+
hard_link_str :: (fn(src: str, dst: str, using(io : IO)) -> Impl(Future(unit, IO, Exception)))
|
|
236
|
+
hard_link(Path.new(String.from(src)), Path.new(String.from(dst)))
|
|
231
237
|
;
|
|
232
238
|
|
|
233
239
|
// Create a symbolic link at dst pointing to src.
|
|
234
|
-
symlink :: (fn(src: Path, dst: Path, using(io : IO)) -> Impl(Future(
|
|
235
|
-
io.async((using(io
|
|
240
|
+
symlink :: (fn(src: Path, dst: Path, using(io : IO)) -> Impl(Future(unit, IO, Exception)))(
|
|
241
|
+
io.async((using(io, exn)) => {
|
|
236
242
|
src_cstr_bytes := src.to_string().to_cstr();
|
|
237
243
|
src_cstr := src_cstr_bytes.ptr().unwrap();
|
|
238
244
|
dst_cstr_bytes := dst.to_string().to_cstr();
|
|
239
245
|
dst_cstr := dst_cstr_bytes.ptr().unwrap();
|
|
240
246
|
result := io.await(IO_dir.symlink(src_cstr, AT_FDCWD, dst_cstr));
|
|
241
247
|
cond(
|
|
242
|
-
(result < i32(0)) => .
|
|
243
|
-
true =>
|
|
248
|
+
(result < i32(0)) => exn.throw(dyn IOError.from_errno((i32(0) - result))),
|
|
249
|
+
true => ()
|
|
244
250
|
)
|
|
245
251
|
})
|
|
246
252
|
);
|
|
247
253
|
|
|
248
|
-
symlink_str :: (fn(src: str, dst: str, using(io : IO)) -> Impl(Future(
|
|
249
|
-
symlink(Path.new(String.from(src)), Path.new(String.from(dst))
|
|
254
|
+
symlink_str :: (fn(src: str, dst: str, using(io : IO)) -> Impl(Future(unit, IO, Exception)))
|
|
255
|
+
symlink(Path.new(String.from(src)), Path.new(String.from(dst)))
|
|
250
256
|
;
|
|
251
257
|
|
|
252
258
|
// ============================================================================
|
|
@@ -254,69 +260,66 @@ symlink_str :: (fn(src: str, dst: str, using(io : IO)) -> Impl(Future(Result(uni
|
|
|
254
260
|
// ============================================================================
|
|
255
261
|
|
|
256
262
|
// Read directory entries from a path.
|
|
257
|
-
read_dir :: (fn(path: Path, using(io : IO)) -> Impl(Future(
|
|
258
|
-
io.async((using(io
|
|
263
|
+
read_dir :: (fn(path: Path, using(io : IO)) -> Impl(Future(ArrayList(DirEntry), IO, Exception)))(
|
|
264
|
+
io.async((using(io, exn)) => {
|
|
259
265
|
cstr_bytes := path.to_string().to_cstr();
|
|
260
266
|
cstr := cstr_bytes.ptr().unwrap();
|
|
261
267
|
// Open the directory
|
|
262
268
|
fd_result := io.await(IO_file.openat(AT_FDCWD, cstr, (O_RDONLY | O_DIRECTORY), i32(0)));
|
|
263
269
|
cond(
|
|
264
|
-
(fd_result < i32(0)) => .
|
|
265
|
-
true =>
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
);
|
|
297
|
-
entries.push(DirEntry(
|
|
298
|
-
name: name,
|
|
299
|
-
file_type: ft,
|
|
300
|
-
ino: IO_dir.dirent_ino(entry_ptr)
|
|
301
|
-
));
|
|
302
|
-
}
|
|
270
|
+
(fd_result < i32(0)) => exn.throw(dyn IOError.from_errno((i32(0) - fd_result))),
|
|
271
|
+
true => ()
|
|
272
|
+
);
|
|
273
|
+
fd := fd_result;
|
|
274
|
+
entries := ArrayList(DirEntry).new();
|
|
275
|
+
buf_size := u32(4096);
|
|
276
|
+
buf := *(u8)(malloc(usize(buf_size)).unwrap());
|
|
277
|
+
while runtime(true), {
|
|
278
|
+
n := io.await(IO_dir.getdents(fd, buf, buf_size));
|
|
279
|
+
cond(
|
|
280
|
+
(n < i32(0)) => {
|
|
281
|
+
free(.Some(*(void)(buf)));
|
|
282
|
+
io.await(IO_file.close(fd));
|
|
283
|
+
exn.throw(dyn IOError.from_errno((i32(0) - n)));
|
|
284
|
+
},
|
|
285
|
+
(n == i32(0)) => { break; },
|
|
286
|
+
true => {
|
|
287
|
+
offset := usize(0);
|
|
288
|
+
while runtime((offset < usize(n))), {
|
|
289
|
+
entry_ptr := (buf &+ offset);
|
|
290
|
+
name_ptr := IO_dir.dirent_name(entry_ptr);
|
|
291
|
+
name := String.from_cstr(name_ptr).unwrap();
|
|
292
|
+
// Skip "." and ".."
|
|
293
|
+
cond(
|
|
294
|
+
((name == String.from(".")) || (name == String.from(".."))) => (),
|
|
295
|
+
true => {
|
|
296
|
+
dt := IO_dir.dirent_type(entry_ptr);
|
|
297
|
+
ft := cond(
|
|
298
|
+
(dt == DT_REG) => FileType.File,
|
|
299
|
+
(dt == DT_DIR) => FileType.Directory,
|
|
300
|
+
(dt == DT_LNK) => FileType.Symlink,
|
|
301
|
+
true => FileType.Other
|
|
303
302
|
);
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
303
|
+
entries.push(DirEntry(
|
|
304
|
+
name: name,
|
|
305
|
+
file_type: ft,
|
|
306
|
+
ino: IO_dir.dirent_ino(entry_ptr)
|
|
307
|
+
));
|
|
308
|
+
}
|
|
309
|
+
);
|
|
310
|
+
offset = (offset + usize(IO_dir.dirent_reclen(entry_ptr)));
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
);
|
|
314
|
+
};
|
|
315
|
+
free(.Some(*(void)(buf)));
|
|
316
|
+
io.await(IO_file.close(fd));
|
|
317
|
+
entries
|
|
315
318
|
})
|
|
316
319
|
);
|
|
317
320
|
|
|
318
|
-
read_dir_str :: (fn(path: str, using(io : IO)) -> Impl(Future(
|
|
319
|
-
read_dir(Path.new(String.from(path))
|
|
321
|
+
read_dir_str :: (fn(path: str, using(io : IO)) -> Impl(Future(ArrayList(DirEntry), IO, Exception)))
|
|
322
|
+
read_dir(Path.new(String.from(path)))
|
|
320
323
|
;
|
|
321
324
|
|
|
322
325
|
export
|