zig-paths.tri (994B)
1 !import io_v2 as IO 2 !export paths 3 !export observe 4 !export badDirectory 5 !export failedRename 6 7 category (t, ([name _ _ _], t)) = name 8 category _ = "unexpected" 9 paths directory source target = IO.io <| IO.scope (owner : do IO.require 10 IO.createDirectory directory 11 file <- IO.openWriter owner source 12 IO.writeSome file [97 98 99] 13 IO.close file 14 before <- IO.statPath source 15 dir <- IO.statPath directory 16 IO.renamePath source target 17 after <- IO.lstatPath target 18 IO.syncDirectory directory 19 IO.bind (IO.statPath source) (missing : do IO.require 20 IO.removeFile target 21 IO.removeDirectory directory 22 IO.pure [before dir after (category missing)])) 23 observe path = IO.io <| do IO.require 24 link <- IO.lstatPath path 25 followed <- IO.statPath path 26 IO.pure [link followed] 27 badDirectory path = IO.io <| IO.bind (IO.syncDirectory path) (reply : IO.pure (category reply)) 28 failedRename source target = IO.io <| IO.bind (IO.renamePath source target) (reply : IO.pure (category reply))