@@ -239,38 +239,6 @@ pub async fn remove(path : StringView) -> Unit {
239239 @event_loop .remove (path , context = "@fs.remove()" )
240240}
241241
242- ///|
243- /// Determine how an offset is interpreted when seeking in a file:
244- /// - `FromStart`: absolute offset from the start of the file
245- /// - `FromEnd`: offset is relative to end of file
246- /// - `Relative`: offset is relative to current position in the file
247- pub (all ) enum SeekMode {
248- FromStart = 0
249- FromEnd
250- Relative
251- }
252-
253- ///|
254- fn SeekMode ::to_int (self : SeekMode ) -> Int = "%identity"
255-
256- ///|
257- /// Change current position in file for reading and writing.
258- /// Can only be applied to a regular file, otherwise `seek` will fail.
259- /// The offset is interpreted using `mode`, see `SeekMode` for more detail.
260- /// Current position in the file after seeking (relative to start of file)
261- /// will be returned.
262- #deprecated ("use `read_at` or `write_at` instead" , skip_current_package = true )
263- pub async fn File ::seek (self : File , offset : Int64 , mode ~ : SeekMode ) -> Int64 {
264- self .io.seek (offset , mode .to_int (), context = "@fs.File::seek()" )
265- }
266-
267- ///|
268- /// Get current position in the file. Can only be applied to a regular file.
269- #deprecated ("use `read_at` or `write_at` instead" , skip_current_package = true )
270- pub async fn File ::curr_pos (self : File ) -> Int64 {
271- self .seek (0 , mode = Relative )
272- }
273-
274242///|
275243/// Get the size of the file. This method will not change position in the file.
276244/// Can only be applied to a regular file.
@@ -281,9 +249,6 @@ pub async fn File::size(self : File) -> Int64 {
281249///|
282250extern "C" fn as_dir_ffi (fd : Int ) -> Directory = "fdopendir"
283251
284- ///|
285- extern "C" fn Directory ::is_null (dir : Directory ) -> Bool = "moonbitlang_async_dir_is_null"
286-
287252///|
288253/// Convert a file to directory.
289254/// If the file is not a directory, an error will be raised.
@@ -295,7 +260,7 @@ extern "C" fn Directory::is_null(dir : Directory) -> Bool = "moonbitlang_async_d
295260pub fn File ::as_dir (self : File ) -> Directory raise {
296261 let fd = self .io.detach_from_event_loop ()
297262 let dir = as_dir_ffi (fd )
298- if dir . is_null ( ) {
263+ if @c_buffer . ptr_is_null ( dir ) {
299264 let context = "@fs.File::as_dir()"
300265 @fd_util .close (fd , context ~)
301266 @os_error .check_errno (context )
@@ -406,6 +371,10 @@ pub async fn symlink(target~ : StringView, path : StringView) -> Unit {
406371 @event_loop .symlink (target , path , context = "@fs.link()" )
407372}
408373
374+ ///|
375+ #borrow (path )
376+ extern "C" fn chmod_ffi (path : Bytes , mode : Int ) -> Int = "moonbitlang_async_chmod"
377+
409378///|
410379/// Change the permission of a file.
411380/// Permission is represented as an integer in UNIX permission style.
@@ -414,5 +383,18 @@ pub async fn symlink(target~ : StringView, path : StringView) -> Unit {
414383/// - users in the owner group of the file can read the file (`4`)
415384/// - other users can do nothing to the file
416385pub async fn chmod (path : StringView , mode : Int ) -> Unit {
417- @event_loop .chmod (path , mode , context = "@fs.chmod()" )
386+ struct Job {
387+ path : Bytes
388+ mode : Int
389+ mut err : Int
390+ }
391+ let path_bytes = @encoding/utf8 .encode (path )
392+ let job : Job = { path : path_bytes , mode , err : 0 }
393+ @event_loop .perform_job_in_worker (job , job => if chmod_ffi (job .path, job .mode) <
394+ 0 {
395+ job .err = @os_error .get_errno ()
396+ })
397+ if job .err != 0 {
398+ raise @os_error .OSError (job .err, context = "@fs.chmod(\{ repr (path )} )" )
399+ }
418400}
0 commit comments