@@ -13,6 +13,9 @@ module [
1313 is_executable!,
1414 is_readable!,
1515 is_writable!,
16+ time_accessed!,
17+ time_modified!,
18+ time_created!,
1619 type!,
1720 open_reader!,
1821 open_reader_with_capacity!,
@@ -25,6 +28,7 @@ import Path exposing [Path]
2528import InternalIOErr
2629import Host
2730import InternalPath
31+ import Utc exposing [Utc ]
2832
2933## Tag union of possible errors when reading and writing a file or directory.
3034##
@@ -213,28 +217,65 @@ is_sym_link! = |path_str|
213217
214218## Checks if the file has the execute permission for the current process.
215219##
216- ## This uses rust [std::fs::Metadata](https://doc.rust-lang.org/std/fs/struct.Metadata.html)
220+ ## This uses rust [std::fs::Metadata](https://doc.rust-lang.org/std/fs/struct.Metadata.html).
217221is_executable ! : Str => Result Bool [PathErr IOErr ]
218222is_executable ! = |path_str|
219223 Host . file_is_executable !(InternalPath . to_bytes (Path . from_str (path_str )))
220224 |> Result . map_err (|err | PathErr (InternalIOErr . handle_err (err )))
221225
222226## Checks if the file has the readable permission for the current process.
223227##
224- ## This uses rust [std::fs::Metadata](https://doc.rust-lang.org/std/fs/struct.Metadata.html)
228+ ## This uses rust [std::fs::Metadata](https://doc.rust-lang.org/std/fs/struct.Metadata.html).
225229is_readable ! : Str => Result Bool [PathErr IOErr ]
226230is_readable ! = |path_str|
227231 Host . file_is_readable !(InternalPath . to_bytes (Path . from_str (path_str )))
228232 |> Result . map_err (|err | PathErr (InternalIOErr . handle_err (err )))
229233
230234## Checks if the file has the writeable permission for the current process.
231235##
232- ## This uses rust [std::fs::Metadata](https://doc.rust-lang.org/std/fs/struct.Metadata.html)
236+ ## This uses rust [std::fs::Metadata](https://doc.rust-lang.org/std/fs/struct.Metadata.html).
233237is_writable ! : Str => Result Bool [PathErr IOErr ]
234238is_writable ! = |path_str|
235239 Host . file_is_writable !(InternalPath . to_bytes (Path . from_str (path_str )))
236240 |> Result . map_err (|err | PathErr (InternalIOErr . handle_err (err )))
237241
242+ ## Returns the time when the file was last accessed.
243+ ##
244+ ## This uses [rust's std::fs::Metadata::accessed](https://doc.rust-lang.org/std/fs/struct.Metadata.html#method.accessed).
245+ ## Note that this is [not guaranteed to be correct in all cases](https://doc.rust-lang.org/std/fs/struct.Metadata.html#method.accessed).
246+ ##
247+ ## NOTE: these functions will not work if basic-cli was built with musl, which is the case for the normal tar.br URL release.
248+ ## See https://github.com/roc-lang/basic-cli?tab=readme-ov-file#running-locally to build basic-cli without musl.
249+ time_accessed ! : Str => Result Utc [PathErr IOErr ]
250+ time_accessed ! = |path_str|
251+ Host . file_time_accessed !(InternalPath . to_bytes (Path . from_str (path_str )))
252+ |> Result . map_ok (|time_u128 | Num . to_i128 (time_u128 ) |> Utc . from_nanos_since_epoch )
253+ |> Result . map_err (|err | PathErr (InternalIOErr . handle_err (err )))
254+
255+ ## Returns the time when the file was last modified.
256+ ##
257+ ## This uses [rust's std::fs::Metadata::modified](https://doc.rust-lang.org/std/fs/struct.Metadata.html#method.modified).
258+ ##
259+ ## NOTE: these functions will not work if basic-cli was built with musl, which is the case for the normal tar.br URL release.
260+ ## See https://github.com/roc-lang/basic-cli?tab=readme-ov-file#running-locally to build basic-cli without musl.
261+ time_modified ! : Str => Result Utc [PathErr IOErr ]
262+ time_modified ! = |path_str|
263+ Host . file_time_modified !(InternalPath . to_bytes (Path . from_str (path_str )))
264+ |> Result . map_ok (|time_u128 | Num . to_i128 (time_u128 ) |> Utc . from_nanos_since_epoch )
265+ |> Result . map_err (|err | PathErr (InternalIOErr . handle_err (err )))
266+
267+ ## Returns the time when the file was created.
268+ ##
269+ ## This uses [rust's std::fs::Metadata::created](https://doc.rust-lang.org/std/fs/struct.Metadata.html#method.created).
270+ ##
271+ ## NOTE: these functions will not work if basic-cli was built with musl, which is the case for the normal tar.br URL release.
272+ ## See https://github.com/roc-lang/basic-cli?tab=readme-ov-file#running-locally to build basic-cli without musl.
273+ time_created ! : Str => Result Utc [PathErr IOErr ]
274+ time_created ! = |path_str|
275+ Host . file_time_created !(InternalPath . to_bytes (Path . from_str (path_str )))
276+ |> Result . map_ok (|time_u128 | Num . to_i128 (time_u128 ) |> Utc . from_nanos_since_epoch )
277+ |> Result . map_err (|err | PathErr (InternalIOErr . handle_err (err )))
278+
238279## Return the type of the path if the path exists on disk.
239280## This uses [rust's std::path::is_symlink](https://doc.rust-lang.org/std/path/struct.Path.html#method.is_symlink).
240281##
0 commit comments