@@ -10,6 +10,9 @@ module [
1010 is_dir!,
1111 is_file!,
1212 is_sym_link!,
13+ is_executable!,
14+ is_readable!,
15+ is_writable!,
1316 type!,
1417 open_reader!,
1518 open_reader_with_capacity!,
@@ -67,8 +70,8 @@ IOErr : InternalIOErr.IOErr
6770## >
6871## > [Path.write!] does the same thing, except it takes a [Path] instead of a [Str].
6972write ! : val, Str , fmt => Result {} [FileWriteErr Path IOErr ] where val implements Encoding , fmt implements EncoderFormatting
70- write ! = |val, path , fmt|
71- Path . write !(val , Path . from_str (path ), fmt)
73+ write ! = |val, path_str , fmt|
74+ Path . write !(val , Path . from_str (path_str ), fmt)
7275
7376## Writes bytes to a file.
7477##
@@ -83,8 +86,8 @@ write! = |val, path, fmt|
8386## >
8487## > [Path.write_bytes!] does the same thing, except it takes a [Path] instead of a [Str].
8588write_bytes ! : List U8 , Str => Result {} [FileWriteErr Path IOErr ]
86- write_bytes ! = |bytes, path |
87- Path . write_bytes !(bytes , Path . from_str (path ))
89+ write_bytes ! = |bytes, path_str |
90+ Path . write_bytes !(bytes , Path . from_str (path_str ))
8891
8992## Writes a [Str] to a file, encoded as [UTF-8](https://en.wikipedia.org/wiki/UTF-8).
9093##
@@ -99,8 +102,8 @@ write_bytes! = |bytes, path|
99102## >
100103## > [Path.write_utf8!] does the same thing, except it takes a [Path] instead of a [Str].
101104write_utf8 ! : Str , Str => Result {} [FileWriteErr Path IOErr ]
102- write_utf8 ! = |str, path |
103- Path . write_utf8 !(str , Path . from_str (path ))
105+ write_utf8 ! = |str, path_str |
106+ Path . write_utf8 !(str , Path . from_str (path_str ))
104107
105108## Deletes a file from the filesystem.
106109##
@@ -123,8 +126,8 @@ write_utf8! = |str, path|
123126## >
124127## > [Path.delete!] does the same thing, except it takes a [Path] instead of a [Str].
125128delete ! : Str => Result {} [FileWriteErr Path IOErr ]
126- delete ! = |path |
127- Path . delete !(Path . from_str (path ))
129+ delete ! = |path_str |
130+ Path . delete !(Path . from_str (path_str ))
128131
129132## Reads all the bytes in a file.
130133##
@@ -139,8 +142,8 @@ delete! = |path|
139142## >
140143## > [Path.read_bytes!] does the same thing, except it takes a [Path] instead of a [Str].
141144read_bytes ! : Str => Result (List U8 ) [FileReadErr Path IOErr ]
142- read_bytes ! = |path |
143- Path . read_bytes !(Path . from_str (path ))
145+ read_bytes ! = |path_str |
146+ Path . read_bytes !(Path . from_str (path_str ))
144147
145148## Reads a [Str] from a file containing [UTF-8](https://en.wikipedia.org/wiki/UTF-8)-encoded text.
146149##
@@ -156,8 +159,8 @@ read_bytes! = |path|
156159##
157160## > [Path.read_utf8!] does the same thing, except it takes a [Path] instead of a [Str].
158161read_utf8 ! : Str => Result Str [FileReadErr Path IOErr , FileReadUtf8Err Path _ ]
159- read_utf8 ! = |path |
160- Path . read_utf8 !(Path . from_str (path ))
162+ read_utf8 ! = |path_str |
163+ Path . read_utf8 !(Path . from_str (path_str ))
161164
162165# read : Str, fmt => Result contents [FileReadErr Path ReadErr, FileReadDecodingFailed] where contents implements Decoding, fmt implements DecoderFormatting
163166# read = |path, fmt|
@@ -172,8 +175,8 @@ read_utf8! = |path|
172175##
173176## > [Path.hard_link!] does the same thing, except it takes a [Path] instead of a [Str].
174177hard_link ! : Str => Result {} [LinkErr IOErr ]
175- hard_link ! = |path |
176- Path . hard_link !(Path . from_str (path ))
178+ hard_link ! = |path_str |
179+ Path . hard_link !(Path . from_str (path_str ))
177180
178181## Returns True if the path exists on disk and is pointing at a directory.
179182## Returns False if the path exists and it is not a directory. If the path does not exist,
@@ -183,8 +186,8 @@ hard_link! = |path|
183186##
184187## > [Path.is_dir!] does the same thing, except it takes a [Path] instead of a [Str].
185188is_dir ! : Str => Result Bool [PathErr IOErr ]
186- is_dir ! = |path |
187- Path . is_dir !(Path . from_str (path ))
189+ is_dir ! = |path_str |
190+ Path . is_dir !(Path . from_str (path_str ))
188191
189192## Returns True if the path exists on disk and is pointing at a regular file.
190193## Returns False if the path exists and it is not a file. If the path does not exist,
@@ -194,8 +197,8 @@ is_dir! = |path|
194197##
195198## > [Path.is_file!] does the same thing, except it takes a [Path] instead of a [Str].
196199is_file ! : Str => Result Bool [PathErr IOErr ]
197- is_file ! = |path |
198- Path . is_file !(Path . from_str (path ))
200+ is_file ! = |path_str |
201+ Path . is_file !(Path . from_str (path_str ))
199202
200203## Returns True if the path exists on disk and is pointing at a symbolic link.
201204## Returns False if the path exists and it is not a symbolic link. If the path does not exist,
@@ -205,16 +208,40 @@ is_file! = |path|
205208##
206209## > [Path.is_sym_link!] does the same thing, except it takes a [Path] instead of a [Str].
207210is_sym_link ! : Str => Result Bool [PathErr IOErr ]
208- is_sym_link ! = |path|
209- Path . is_sym_link !(Path . from_str (path ))
211+ is_sym_link ! = |path_str|
212+ Path . is_sym_link !(Path . from_str (path_str ))
213+
214+ ## Checks if the file has the execute permission for the current process.
215+ ##
216+ ## This uses rust [std::fs::Metadata](https://doc.rust-lang.org/std/fs/struct.Metadata.html)
217+ is_executable ! : Str => Result Bool [PathErr IOErr ]
218+ is_executable ! = |path_str|
219+ Host . file_is_executable !(InternalPath . to_bytes (Path . from_str (path_str )))
220+ |> Result . map_err (|err | PathErr (InternalIOErr . handle_err (err )))
221+
222+ ## Checks if the file has the readable permission for the current process.
223+ ##
224+ ## This uses rust [std::fs::Metadata](https://doc.rust-lang.org/std/fs/struct.Metadata.html)
225+ is_readable ! : Str => Result Bool [PathErr IOErr ]
226+ is_readable ! = |path_str|
227+ Host . file_is_readable !(InternalPath . to_bytes (Path . from_str (path_str )))
228+ |> Result . map_err (|err | PathErr (InternalIOErr . handle_err (err )))
229+
230+ ## Checks if the file has the writeable permission for the current process.
231+ ##
232+ ## This uses rust [std::fs::Metadata](https://doc.rust-lang.org/std/fs/struct.Metadata.html)
233+ is_writable ! : Str => Result Bool [PathErr IOErr ]
234+ is_writable ! = |path_str|
235+ Host . file_is_writable !(InternalPath . to_bytes (Path . from_str (path_str )))
236+ |> Result . map_err (|err | PathErr (InternalIOErr . handle_err (err )))
210237
211238## Return the type of the path if the path exists on disk.
212239## This uses [rust's std::path::is_symlink](https://doc.rust-lang.org/std/path/struct.Path.html#method.is_symlink).
213240##
214241## > [Path.type!] does the same thing, except it takes a [Path] instead of a [Str].
215242type ! : Str => Result [IsFile , IsDir , IsSymLink ] [PathErr IOErr ]
216- type ! = |path |
217- Path . type !(Path . from_str (path ))
243+ type ! = |path_str |
244+ Path . type !(Path . from_str (path_str ))
218245
219246Reader := { reader : Host . FileReader , path : Path }
220247
0 commit comments