Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.mbt.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ test "copy text between files" {
e => raise e
}
@miniio.mkdir(dir)
defer ignore(try? @miniio.rmdir(dir, recursive=true))
defer (@miniio.rmdir(dir, recursive=true) catch { _ => () })

@miniio.write_text_file(dir + "/input.txt", "hello\n")
@miniio.copy_file(dir + "/input.txt", dir + "/output.txt")
Expand All @@ -92,7 +92,7 @@ test "append log file" {
e => raise e
}
@miniio.mkdir(dir)
defer ignore(try? @miniio.rmdir(dir, recursive=true))
defer (@miniio.rmdir(dir, recursive=true) catch { _ => () })

let path = dir + "/tool.log"
@miniio.write_text_file(path, "start\n")
Expand All @@ -111,7 +111,7 @@ test "read and write json" {
e => raise e
}
@miniio.mkdir(dir)
defer ignore(try? @miniio.rmdir(dir, recursive=true))
defer (@miniio.rmdir(dir, recursive=true) catch { _ => () })

let path = dir + "/manifest.json"
@miniio.write_json_file(path, { "name": "miniio", "portable": true })
Expand Down
9 changes: 9 additions & 0 deletions example/cli_tools/moon.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name = "moonbit-community/miniio-example-cli-tools"

version = "0.1.0"

import {
"moonbit-community/miniio@0.2.0",
}

preferred_target = "wasm"
8 changes: 0 additions & 8 deletions example/cli_tools/moon.mod.json

This file was deleted.

10 changes: 10 additions & 0 deletions example/lottie_manifest/moon.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name = "moonbit-community/miniio-example-lottie-manifest"

version = "0.1.0"

import {
"moonbit-community/miniio@0.2.0",
"cg-zhou/moon_lottie@0.3.0",
}

preferred_target = "wasm"
9 changes: 0 additions & 9 deletions example/lottie_manifest/moon.mod.json

This file was deleted.

2 changes: 1 addition & 1 deletion example/lottie_manifest/moon.pkg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
"moonbit-community/miniio",
"cg-zhou/moon_lottie/lib/parser" @parser,
"cg-zhou/moon_lottie/lib/parser",
"moonbitlang/core/json",
}

Expand Down
10 changes: 10 additions & 0 deletions example/morm_query/moon.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name = "moonbit-community/miniio-example-morm-query"

version = "0.1.0"

import {
"moonbit-community/miniio@0.2.0",
"oboard/morm@0.3.15",
}

preferred_target = "wasm"
9 changes: 0 additions & 9 deletions example/morm_query/moon.mod.json

This file was deleted.

2 changes: 1 addition & 1 deletion example/morm_query/moon.pkg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
"moonbit-community/miniio",
"oboard/morm",
"oboard/morm/engine" @engine,
"oboard/morm/engine",
}

supported_targets = "wasm"
Expand Down
6 changes: 3 additions & 3 deletions fd.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ pub fn File::tell(self : File) -> UInt64 raise Errno {
}

///|
pub impl @io.Reader for File with _get_internal_buffer(self) {
pub impl @io.Reader for File with fn _get_internal_buffer(self) {
self.read_buf
}

///|
pub impl @io.Reader for File with _direct_read(self, buf, offset~, max_len~) {
pub impl @io.Reader for File with fn _direct_read(self, buf, offset~, max_len~) {
wrap(() => self.raw.read(buf, offset~, max_len~))
}

///|
pub impl @io.Writer for File with write_once(self, data) {
pub impl @io.Writer for File with fn write_once(self, data) {
wrap(() => self.raw.write_once(data))
}
25 changes: 22 additions & 3 deletions fs.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,21 @@ pub fn open(
mode? : Mode = ReadOnly,
append? : Bool = false,
create_mode? : CreateMode = OpenExisting,
follow_symlink? : Bool = true,
) -> File raise Errno {
{
raw: wrap(() => {
let lookup_flags = if follow_symlink {
@raw.LookupFlags::new().symlink_follow()
} else {
@raw.LookupFlags::new()
}
@raw.open(
path,
mode=mode.to_raw(),
append~,
create_mode=create_mode.to_raw(),
lookup_flags~,
)
}),
read_buf: @io.ReaderBuffer::new(),
Expand All @@ -54,7 +61,7 @@ pub fn open(

///|
pub fn create(path : StringView) -> File raise Errno {
{ raw: wrap(() => @raw.create(path)), read_buf: @io.ReaderBuffer::new() }
open(path, mode=WriteOnly, create_mode=CreateOrTruncate)
}

///|
Expand Down Expand Up @@ -85,8 +92,14 @@ pub fn readdir(
path : StringView,
include_hidden? : Bool = true,
sort? : Bool = false,
follow_symlink? : Bool = true,
Comment thread
peter-jerry-ye marked this conversation as resolved.
) -> Array[String] raise Errno {
let result = wrap(() => @raw.readdir_names(path))
let lookup_flags = if follow_symlink {
@raw.LookupFlags::new().symlink_follow()
} else {
@raw.LookupFlags::new()
}
let result = wrap(() => @raw.readdir_names(path, lookup_flags~))
let result = if include_hidden {
result
} else {
Expand Down Expand Up @@ -147,7 +160,13 @@ pub fn is_file(path : StringView) -> Bool raise Errno {
///|
pub fn rmdir(path : StringView, recursive? : Bool = false) -> Unit raise Errno {
if recursive {
for entry in readdir(path, include_hidden=true, sort=false) {
for
entry in readdir(
path,
include_hidden=true,
sort=false,
follow_symlink=false,
) {
let entry_path = path.to_owned() + "/" + entry
remove(entry_path) catch {
Notempty => rmdir(entry_path, recursive=true)
Expand Down
Loading
Loading