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:
Josh Goebel
2021-05-01 22:58:17 +00:00
parent 5118fb6561
commit 27cf54d449
7 changed files with 125 additions and 56 deletions
+23
View File
@@ -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