feat: add Directory.create/delete and refactor io module to use Scheduler.await_
Add foreign static methods `create_` and `delete_` to the Directory class in the Wren io module, backed by C implementations using `uv_fs_mkdir` and `uv_fs_rmdir` with proper error handling via `schedulerResumeError`. Refactor existing `Directory.list` and `File.delete` to use the new `Scheduler.await_` helper instead of manually calling `runNextScheduled_`, and rename `ensurePath_` to `ensureString_` for consistency across both classes. Introduce a new test file `create_delete.wren` that validates directory creation, existence checks, and deletion on both POSIX and Windows platforms.
This commit is contained in:
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
import "io" for Directory, Stat
|
||||
import "os" for Platform
|
||||
|
||||
if (Directory.exists("tmp")) {
|
||||
Directory.delete("tmp")
|
||||
}
|
||||
|
||||
System.print(Directory.exists("tmp")) // expect: false
|
||||
Directory.create("tmp")
|
||||
System.print(Directory.exists("tmp")) // expect: true
|
||||
|
||||
// Windows does not support mode
|
||||
if (Platform.isPosix) {
|
||||
var stat = Stat.path("tmp")
|
||||
// 511 is 0755
|
||||
System.print(stat.mode && 0x1ff) // expect: 511
|
||||
}
|
||||
|
||||
Directory.delete("tmp")
|
||||
System.print(Directory.exists("tmp")) // expect: false
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user